0
我使用下面的代碼下載PDF文檔,但保存爲模式,但IE中存在問題, 任何人都可以解決此問題?下載另存爲對話框的PDF文檔
private void DownloadFile(string fname, bool forceDownload)
{
string path = MapPath(fname);
string name = Path.GetFileName(fname);
string ext = Path.GetExtension(fname);
string type = "";
Response.ClearHeaders();
Response.ClearContent();
// set known types based on file extension
if (ext != null)
{
switch (ext.ToLower())
{
case ".htm":
case ".html":
type = "text/HTML";
break;
case ".txt":
type = "text/plain";
break;
case ".pdf":
type = "application/pdf";
break;
case ".doc":
case ".docx":
case ".rtf":
type = "Application/msword";
break;
}
}
if (forceDownload)
{
Response.AppendHeader("content-disposition", "attachment; filename=" + name);
}
if (type != "")
{
Response.ContentType = type;
Response.WriteFile(path);
Response.End();
}
}
感謝
阿西姆哈什米
問題是什麼?是拋出異常或JS錯誤,或文件操作系統沒有下載到客戶端電腦? – 2010-11-03 14:10:51