Last post Apr 23, 2015 08:43 PM by Paul Linton
Apr 23, 2015 03:25 PM|Zaara|LINK
I'm using StreamWriter to save data in csv file. below is the snippet.
TextWriter sw = new StreamWriter ("C:\\Data.csv");
string strData = "Zaara";
float floatData = "324.563";
I'm expecting zaara in first column and 324.56 in second column.
But im facing weird issue like zaara in first column, 324 in second column and 56 in third column.
Not sure what is happening.! Can any one help me with this.
Apr 23, 2015 05:03 PM|gerrylowry|LINK
@Zaara welcome to forums.asp.net
the most likely cause is your globalization settings.
Your system is likely set up to default to comma as your decimal point..
You need to change that.
example, see https://msdn.microsoft.com/en-us/library/system.globalization.numberformatinfo.numberdecimalseparator(v=vs.110).aspx
Zaara, do this to test my theory:
Your output will likely be a comma.
Apr 23, 2015 05:28 PM|JohnBert|LINK
if you want to do it a bit more elegant you could do something like that:
sing(StreamWriter swOutputFile = new StreamWriter(new FileStream("C:\\Dev\\AppendedJobData.csv", FileMode.Create, FileAccess.Write, FileShare.Read)))
//Get nodes from returned XML ticket
XmlNodeList xmlJobs = xdResults.SelectNodes("/Updates/Jobs/Job");
//Pull out data from XML attributes
foreach (XmlElement xeJobUpdate in xmlJobs)
List<String> lineItems = new List<String>();
//add all the other items
//after the loop you close the writer
//all the work is done much easier
Apr 23, 2015 08:43 PM|Paul Linton|LINK
Open the Data.csv file using notepad and you will see the problem.