我正在尝试在ashx文件中使用DataTableReader从DataTable中读取数据,然后将其转换为byte[]数组,创建Excel文件。但是它并没有起作用。这里是一些代码:
DataTableReader RS = dt.CreateDataReader();
byte[] byteArray = GetData(RS);
context.Response.ContentType = "application/ms-excel";
context.Response.Clear();
// context.Response.Charset = "";
try
{
context.Response.BinaryWrite(byteArray);
context.Response.OutputStream.Write(byteArray, 0, byteArray.Length);
context.Response.BufferOutput = true;
context.Response.Flush();
}
catch (Exception ex)
{
SendMail(ex.Message.ToString());
}
它抛出以下异常:
context.Response.SubStatusCode 抛出了 System.PlatformNotSupportedException 类型的异常。{"此操作需要 IIS 集成管道模式。"} ashx
我知道如果使用头文件需要 IIS7 或 Framework 3+。
非常感谢您的帮助!