无法下载word文档,抛出异常 [英] Can't download word document, throwing exception

查看:175
本文介绍了无法下载word文档,抛出异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用响应对象下载作为内容存储在数据库中的单词文档。它抛出以下异常:

I'm using response object to download word document which is stored in database as a content. It is throwing the following exception :

 SubStatusCode 'Response.SubStatusCode' threw an exception of type 'System.PlatformNotSupportedException'
 base {"This operation requires IIS integrated pipeline mode."} System.NotSupportedException  {System.PlatformNotSupportedException}
 Headers 'Response.Headers' threw an exception of type 'System.PlatformNotSupportedException'

我无法查看我的文件..我的代码如下:

I cannot able to view my file.. My code is as follows:

protected void btnResumedload_Click(object sender, EventArgs e)
{
    DataTable dtResumeInfo = new DataTable();

    dtResumeInfo = bc.ConvertByteToDataTable(objservice.getResumeInfo(int.Parse(Session["LoginId"].ToString())));
    if (dtResumeInfo.Rows.Count > 0)
    {
        string doctype = dtResumeInfo.Rows[0]["ContentType"].ToString();
        string docname = dtResumeInfo.Rows[0]["FileName"].ToString();
        //
        try
        {
            Response.Buffer = false;
            Response.ClearHeaders();
            Response.ContentType = doctype;
            Response.AddHeader("Content-Disposition",
                     "attachment; filename=" + docname);
            //
            //Code for streaming the object while writing
            const int ChunkSize = 1024;
            byte[] buffer = new byte[ChunkSize];
            byte[] binary = (dtResumeInfo.Rows[0]["ContentData"]) as byte[];
            MemoryStream ms = new MemoryStream(binary);
            int SizeToWrite = ChunkSize;

            for (int i = 0; i < binary.GetUpperBound(0) - 1; i = i + ChunkSize)
            {
                if (!Response.IsClientConnected) return;
                if (i + ChunkSize >= binary.Length)
                    SizeToWrite = binary.Length - i;
                byte[] chunk = new byte[SizeToWrite];
                ms.Read(chunk, 0, SizeToWrite);
                Response.BinaryWrite(chunk);
                Response.Flush();
            }
            Response.Close();
        }
        catch (Exception ex)
        {
        lblmsg.Visible = true;
        lblmsg.Text = ex.Message;
        }
    }
    else
    {
        lblmsg.Visible = true;
        lblmsg.Text = "No Resume Information Found.";
    }
}


推荐答案

看起来好像您正在使用仅由IIS 7.0集成管道模式支持的Response.Headers属性。请参阅: IIS6 + HttpModule:此操作需要IIS集成管道模式

It appears as though you are using the Response.Headers property which is only supported by the IIS 7.0 integrated pipeline mode. See: IIS6 + HttpModule: This operation requires IIS integrated pipeline mode

这篇关于无法下载word文档,抛出异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆