gpt4 book ai didi

c# - 在IE9中选择 'Open'时Asp.Net下载文件报错

转载 作者:太空狗 更新时间:2023-10-29 17:58:31 24 4
gpt4 key购买 nike

<分区>

我正在使用 Response 让我的应用程序为用户打开一个 Word 文档。如果用户选择保存文件,它会保存它并且文件看起来像您打开它时的样子。如果用户选择立即打开文件,他们会收到一条错误消息,指出 IE 无法打开该文件。如果他们选择“重试”,MS Word 会显示一条错误消息,指出无法找到该文件。以下是显示我的情况的屏幕截图。另外,这是我必须显示文件的代码:

        this.Context.Response.Clear();
this.Context.Response.ClearContent();
this.Context.Response.ClearHeaders();
this.Context.Response.BufferOutput = true;
this.Context.Response.ContentType = "application/msword";
this.Context.Response.AppendHeader("Content-Length", bytes.Length.ToString());
this.Context.Response.AddHeader("Content-Disposition", "attachment; filename=" + "Test Document.doc");
this.Context.Response.BinaryWrite(bytes);
this.Context.ApplicationInstance.CompleteRequest();

这是提示用户下载时的屏幕: enter image description here

这是用户选择“打开”后的屏幕 enter image description here

这是用户选择“重试”后的屏幕。此屏幕适用于 MS Word。 enter image description here

****编辑****我在网上找到了一些代码,我尝试测试过,但在调用此函数时仍然会出现问题:

    protected void GenerateMsWordDoc()
{
string strBody = "<html>" +
"<body>" +
"<div>Your name is: <b>Billy Bob</b></div>" +
"<table width='100%' style='background-color:#cfcfcf;'><tr><td>1st Cell body data</td><td>2nd cell body data</td></tr></table>" +
"Ms Word document generated successfully." +
"</body>" +
"</html>";
string fileName = "MsWordSample.doc";
// You can add whatever you want to add as the HTML and it will be generated as Ms Word docs
Response.AppendHeader("Content-Type", "application/msword");
Response.AppendHeader ("Content-disposition", "attachment; filename="+ fileName);
Response.Write(strBody);
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com