响应,结束()给出错误

时间:2015-03-26 09:15:20

标签: c# .net

以下是我的代码。在response.end()出现此错误:"Unable to evaluate expression because the code is optimized or the native frame is on top of the call stake."

 try
            {
                HttpContext context = HttpContext.Current;
                context.Response.Clear();
                context.Response.Buffer = true;
                context.Response.AddHeader("content-disposition", "attachment;filename=" + filename + ".csv");
                context.Response.Charset = "";
                context.Response.ContentType = "application/text";


                StringBuilder sb = new StringBuilder();
                for (int k = 0; k < dtCsv.Columns.Count; k++)
                {
                    //add separator
                    sb.Append(dtCsv.Columns[k].ColumnName + ',');
                }
                //append new line
                sb.Append("\r\n");
                for (int i = 0; i < dtCsv.Rows.Count; i++)
                {
                    for (int k = 0; k < dtCsv.Columns.Count; k++)
                    {
                        //add separator
                        sb.Append(dtCsv.Rows[i][k].ToString().Replace(",", ";") + ',');
                    }
                    //append new line
                    sb.Append("\r\n");
                }
                context.Response.Output.Write(sb.ToString());
                context.Response.Flush();
                context.Response.End();
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }

0 个答案:

没有答案