0
我需要在客戶機中將文件另存爲.csv。我正在使用下面的代碼。使用response.write()時出現錯誤
protected void btnGen_Click(object sender, EventArgs e)
{
try
{
string fileName = "test";
string attachment = "attachment; filename=" + fileName + ".csv";
List<string> lst1 = new List<string> { "wert", "fds", "hjgfh", "hgfhg" };
List<string> lst2 = new List<string> { "hgfds", "hdfg", "yretg", "treter" };
List<string> lst3 = new List<string> { "hgfdgf", "gfdg", "gfdgf", "ghfdg" };
List<List<string>> lst = new List<List<string>> { lst1, lst2, lst3 };
StringBuilder sb = new ExportFacade().GenerateStringBuilder(lst);
Response.ContentType = "text/csv" ;
lblProgress.ForeColor = System.Drawing.Color.Green;
lblProgress.Text = "File created and write successfully!";
HttpContext.Current.Response.AddHeader("content-disposition", attachment);
Response.Write(sb.ToString());
lblProgress.ForeColor = System.Drawing.Color.Green;
lblProgress.Text = "File created and write successfully!";
Response.Flush();
Response.End();
}
catch (Exception ex)
{
lblProgress.ForeColor = System.Drawing.Color.Red;
lblProgress.Text = "File Saving Failed!";
}
}
我沒有使用更新面板。
當我按一下按鈕我收到以下錯誤
Sys.WebForms.PageRequestManagerParserErrorException:從服務器收到的消息 無法解析。此 錯誤的常見原因是響應通過調用Response.Write(), 響應篩選器,HttpModules或服務器跟蹤已啓用而被修改時。
如果你能幫我擺脫這個問題,對我來說這將是一個很大的幫助。 謝謝。