iis上的打开文档中的问题 [英] problem in Open document on iis
本文介绍了iis上的打开文档中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在从网格视图(Web应用程序)中从服务器打开pdf txt字文件,它在Visual Studio中可以很好地打开,但是当我从iis运行此代码时,它第一次在新窗口中完美打开,但是在另一时间当我打开它时,在同一窗口中打开并显示一些机器类型代码
I m opening the the word pdf txt file from the server from the grid view(Web application) it open fine in visual studio but when i run this code from the iis, it open first time in new window perfectly but another time when i open it that open in same window and shows some machine type code
String path = Server.MapPath(strRequest);
System.IO.FileInfo file = new System.IO.FileInfo(path);
if (file.Exists)
{
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
Response.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(file.FullName);
//Response.End();
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
else
{
lblError.Text = "This file does not exist.";
}
推荐答案
using System.Net;
string pdfPath = Server.MapPath("~/SomePDFFile.pdf");
WebClient client = new WebClient();
Byte[] buffer = client.DownloadData(pdfPath);
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", buffer.Length.ToString());
Response.BinaryWrite(buffer);
或
or
Response.Redirect("~/somePDFFile.pdf");
这篇关于iis上的打开文档中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文