這是一個奇怪的...我有一個CSV文件在服務器上,並通過下面的代碼提供給用戶。通常情況下,設定的結果是正確的,但它總是忽略了最後一個記錄的最後一個字段:System.Web.HttpContext.Current.Response解析字段
有限公司名稱,過程日期,員工標識,姓氏,名字,卡斯特驗證,ENTERED_HRS,勞動型
溫度,2014年2月21日,CONTRACTOR0001,達倫堡,埃裏克,131137057134,5,0
溫度,2014年2月21日,CONTRACTOR0001,達倫堡,埃裏克,1411310002,8,0
溫度2014 -02-21,CONTRACTOR0001,Dahlenburg,Eric,1411320015,6.609,0
Temp,2014- 02-21,CONTRACTOR0001,Dahlenburg,Eric,1413500001105,6
注意在最後一個記錄末尾沒有「,0」?在Visual Studios中,它工作正常,但在我的開發服務器上,它省略了最後一部分。
我確認源CSV文件包含所有數據字段。我嘗試了CSV文件的不同路徑位置,但沒有更改。無法理解爲什麼它在Visual Studios上運行,而不是在服務器上運行。
附錄:我不知道它是否重要,但源文件位於服務器上的虛擬目錄(而非物理)上。有任何想法嗎???
// Causes Save As Dialog box to appear for user.
String FileName = fileName;
String FilePath = strFilePath;
System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
response.ClearContent();
response.Clear();
response.ContentType = "text/csv";
response.AddHeader("Content-Disposition", "attachment; filename=" + FileName + ";");
response.WriteFile(FilePath + FileName);
response.Flush();
response.Close();
// response.End(); // Same as response.TransmitFile(), but causes an exception because it raises the EndRequest event.