Include ZERO before the numbers in CSV file?

3

I need to include ZERO to complete the CPF digits in the csv file, but if the CPF starts with ZERO it is taken and the numbers are only, that is, it has cpf that only saves 9 digits, since the first two do not enter account ...

public string CreateCSVFile(List<ExcelColumsData> registers)
{
    List<string> linesList = new List<string>();
    foreach (var item in registers)
    {
        linesList.Add(item.Licence + ";" + item.CPF.ToString() + ";" + item.CodeANAC + ";" + item.Plate + ";" + item.FullName + ";" + item.BaseContract + ";" + item.IATACODE);
    }

    string fileName = "G3_" + DateTime.Now.ToString("yyyyMMdd") + ".csv";
    FreePassDataContextDataContext dataContext = new FreePassDataContextDataContext(ConfigurationManager.ConnectionStrings["Default"].ConnectionString);
    var freePassConfigurationsEntity = dataContext.FreePassConfigurations.FirstOrDefault();

    string downloadFolderSFTP = "C:\ftp\"; 

    System.IO.File.WriteAllLines(downloadFolderSFTP + fileName, linesList, System.Text.Encoding.GetEncoding("iso-8859-1"));

    return fileName;
}

In the code it appears as a string normally, but no longer in the CSV file. Can you help me?

    
asked by anonymous 05.08.2014 / 22:28

1 answer

2

You can use it as follows:

Convert.ToUInt64(item.CPF.ToString()).ToString(@"000\.000\.000\-00")

This forces the CPF to pass through a mask specified in the second ToString() .

EDIT

For numbers only, use:

String.Format("{0:00000000000}", item.CPF);

I'm assuming that CPF is numeric.

    
05.08.2014 / 22:45