2011-07-06 80 views
0

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

这里是我的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”,但它没有帮助。

任何帮助,将不胜感激。

+0

你的意思是 '它不工作'? IE试图在浏览器中加载PDF而不是保存文件?你可以尝试从其他机器? – Jay

+0

如果我记得的话,IE可能会与Adobe插件古怪。尝试将POST更改为GET,或者有时我们必须打开空白浏览器窗口,然后在打开后将window.location设置为PDF URL。 – sdcoder

+0

它不会加载它或尝试保存它。我正在使用Windows 7,64位虚拟机。它的IE8和我认为它也是64位。我发布的代码在Firefox中工作,但在Chrome和Windows中失败。所以也许有更好的方法来做到这一点。我必须使用的唯一工具(设计要求)是ajax和WCF。 此外,.pdf文件没有网址。这是Intranet Web应用程序的一部分,它允许用户浏览文件夹,选择文件然后下载该文件。 – edepperson

回答

0

找到了解决方案: 设置的ContentType = “应用程序/ x-未知” 然后添加该标头 “内容处置:附件;文件名= 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+";");