`
v5browser
  • 浏览: 1130464 次
社区版块
存档分类
最新评论

.net C# 实现点击下载PDF文件(通知浏览器打开下载对话框) 不是直接打开

 
阅读更多
 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)
            {
                //打开时异常了
               
            }  

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics