Reputation: 1329
I want to create a csv file and save it in a particular folder. My code is as below:
string Name = UserID + "HistoricalRecords.csv";
string fileName = "C:\\Temp\\"+Name;
TextWriter textWriter = new StreamWriter("fileName");
However, I am still getting the above error. I am not saving the file to that path though. Any idea as to why I am getting this error and how can I solve it?
Upvotes: 0
Views: 2608
Reputation: 33573
You are referring literally here:
TextWriter textWriter = new StreamWriter("fileName");
and, because there is no full path given, it goes to the current working directory, which happens to be C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\10.0\
you should use the variable name:
TextWriter textWriter = new StreamWriter(fileName);
Upvotes: 1