无法在IE中保存pdf

时间:2011-07-06 19:50:11

标签: html ajax wcf pdf

我可以在Internet Explorer中下载并保存其他类型的文件,我可以在Firefox中下载和保存pdf类型。但在IE8中,我无法下载pdf文件。我已经检查了wcf代码,它正在返回一个文件流,正如我已经提到的,它可以用于其他类型的文件,例如.xlsx。

这是我在html页面上的表格

<div>
  <form id="frmdownloadData" action="http://localhost:9433/NASWcf1/runDownloadFile" 
     method="post" enctype="multipart/form-data" target="_blank">
  <input type="hidden" id="UserId" name="UserId" value="****" />
  File Name: <input id="filename" name="filename" type="text" value=""/>
  <br />
  App Code: <input id="appcode" name="appcode" type="text" value="Appcode_FileId"  />
  </form>
</div>
<input type="button" id="submitdwnldfrm" onclick="dofileDownload()" />

这是dofileDownload()

的脚本
function dofileDownload() {
        $('#frmdownloadData').ajaxSubmit(function () {
            alert("Thank you for your comment!");
        });
    }

Befopre从wcf返回文件流,我设置了这个属性: System.ServiceModel.Web.WebOperationContext.Current.OutgoingResponse.ContentType =“application / octet-stream”;

我也尝试将其设置为“application / pdf”,但它没有帮助。

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

找到了解决方案: 设置ContentType =“application / x-unknown” 然后添加此标头 “Content-Disposition:attachment; filename = filename.ext;”

以下示例代码:

System.ServiceModel.Web.WebOperationContext.Current.OutgoingResponse.ContentType   = "application/x-unknown";
                System.ServiceModel.Web.WebOperationContext.Current.OutgoingResponse.Headers.Add("Content-Disposition: attachment; filename="+filename+";");