.net C# 实现点击下载PDF文件(通知浏览器打开下载对话框) 不是直接打开
[csharp] string FullFileName = "";
try
{
string FileName = "拓鹏云信接口文档 v2.0.pdf";
FullFileName = Server.MapPath(FileName);
//FileName--要下载的文件名
FileInfo DownloadFile = new FileInfo(FullFileName);
if (DownloadFile.Exists)
{
Response.Clear();
Response.ClearHeaders();
Response.Buffer = false;
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(DownloadFile.FullName, System.Text.Encoding.ASCII));
Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());
Response.WriteFile(DownloadFile.FullName);
Response.Flush();
Response.End();
}
else
{
//文件不存在
}
}
catch(Exception ex)
{
//打开时异常了
}
string FullFileName = "";
try
{
string FileName = "拓鹏云信接口文档 v2.0.pdf";
FullFileName = Server.MapPath(FileName);
//FileName--要下载的文件名
FileInfo DownloadFile = new FileInfo(FullFileName);
if (DownloadFile.Exists)
{
Response.Clear();
Response.ClearHeaders();
Response.Buffer = false;
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(DownloadFile.FullName, System.Text.Encoding.ASCII));
Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());
Response.WriteFile(DownloadFile.FullName);
Response.Flush();
Response.End();
}
else
{
//文件不存在
}
}
catch(Exception ex)
{
//打开时异常了
}
补充:软件开发 , C# ,