How to create .csv file in wp8.1 using C#

Snaini
Posted by Snaini under Windows Phone category on | Points: 40 | Views : 926



string headerTemplate = @"""Project Id""" + "," + @"""Project Name""" + "," + @"""Type""" + "," + @"""PBID""" + "," + @"""Priority""" + "," + @"""Module""" + "," + @"""Phase""" + "," + @"""Title""" + "," + @"""Acceptance Crieteria""" + "," + @"""Status""" + "," + @"""Resource""" + "," + @"""Sprint""" + "," + @"""Comments""" + "," + @"""Estimated Hours""" + "," + @"""Actual Hours""" + "," + @"""Remaining Hours""" + " \n";
foreach (GridViewClass item in viewCollection)
{
headerTemplate += "\"" + item.ProjectId.ToString() + "\"" + "," + "\"" + item.ProjectName + "\"" + "," + "\"" + item.Type + "\"" + "," + "\"" + item.PBID + "\"" + "," + "\"" + item.Priority + "\"" + "," + "\"" + item.Module + "\"" + "," + "\"" + item.Phase + "\"" + "," + "\"" + item.TaskDescription + "\"" + "," + "\"" + item.AcceptanceCriteria + "\"" + "," + "\"" + item.Status + "\"" + "," + "\"" + item.Resource + "\"" + "," + "\"" + item.SprintId + "\"" + "," + "\"" + item.Comments + "\"" + "," + "\"" + item.EstimatedHours.ToString() + "\"" + "," + "\"" + item.ActualHours.ToString() + "\"" + "," + "\"" + item.RemainigHours.ToString() + "\"" + "\n";
}
var localAppFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
var fileHandle = await localAppFolder.CreateFileAsync("File.csv",Windows.Storage.CreationCollisionOption.ReplaceExisting);
await Windows.Storage.FileIO.WriteTextAsync(fileHandle, headerTemplate);


Heare we are using Comma Separated value so according to that .csv file create cell, so if your data having any commas inbetween it will also split and create cell. Instead of creating cells just need to ignore commas by using "\""+string+"\""

Comments or Responses

Login to post response