I have an application that exports the result in a csv file. I'm using commas as a column separator, but the problem is that in one of the output parameters item.SN
the content contains commas to separate the name then the file creates columns separating the data into several parts.
How could I fix this? I have tried several ways but I can not do it.
Thanks in advance.
Here is my code:
foreach (WS.ProjectMetaData proj in pr)
{
string outCsvFile = string.Format(@"C:\ExportTasksForAllProjects\{0}.csv", proj.ProjectTitle + DateTime.Now.ToString("_yyyyMMdd HHmms"));
String newLine = "";
var stream = File.CreateText(outCsvFile);
stream.WriteLine("ProjectName,Subject Name, UserID, Task StartDate");
WS.UserData[] userDataId = client.GetUserData(DataSourceId);
List<string> multiUserIDs = new List<string>();
foreach (var userdata in userDataId)
{
multiUserIDs.Add(userdata.List[0].ToString());
}
string temp = "";
var AllProjectIds = proj.ProjectID;
string[] projectIDs = new string[] { AllProjectIds }; // all projects
WS.TaskEntry[] resultGT3 = client.GetTasks3(projectIDs, multiUserIDs.ToArray());
foreach (var item in resultGT3)
{
newLine = item.ProjectTitle + "," +
item.SN + "," + //Aqui el SN contiene commas entonces se separa en diferentes columnas
item.UserID + "," +
item.StartDate;
stream.WriteLine(newLine);
}
stream.Close();
}