Błędne znaki StreamWriter
Mam problem, w którym streamwriter produkuje błędne znaki w csv, który tworzę. Postaci,ja" , pojawia się tylko na początku pliku:
<code>5,"GEN",555555555,,"Evan","Smith",,,,,,,,,,,,,,,,,,,,,,,,,"[email protected]" 5,"GEN",555555555,,"Dorathy","Smith",,,,,,,,,,,,,,,,,,,,,,,,,"[email protected]" 5,"GEN",555555555,,"Marvin","Smith",,,,,,,,,,,,,,,,,,,,,,,,,"[email protected]" .... </code>
Wygląda mi na problem z kodowaniem. Próbowałem innego kodowania, a także wyrażenia regularnego, aby wyczyścić łańcuch przy odrobinie szczęścia. Oto kod do podglądu (choć nie jest to nic skomplikowanego). Działa również jako proces WWW.
<code>string fileName = includeEmail == false ? "attachment; filename=stuacct_batch.txt" : "attachment; filename=rentals.csv"; Context.Response.Clear(); Context.Response.AddHeader("content-disposition", fileName); Context.Response.ContentType = includeEmail == false ? "text/plain" : "text/csv"; using (StreamWriter sw = new StreamWriter(Response.OutputStream, Encoding.UTF8)) { string line = ""; foreach (Student s in students) { // ... some logic above that that's misc. to this problem line = "5,\"GEN\"," + s.StudentNumber + ",,\"" + s.FirstName + "\",\"" + s.LastName + "\",,,,,,,,,,,,,,,,,,,,,,,,,\"" + s.Email + "\""; sw.WriteLine(line); } } Context.Response.End(); Context.Response.Flush(); Context.ApplicationInstance.CompleteRequest(); </code>