.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)
            {
                //打开时异常了
               
            }  

展开阅读全文

没有更多推荐了,返回首页