龙空技术网

asp.net显示查看PDF文件内容和下载文件到本地的两种方式

洞悉科学 177

前言:

目前小伙伴们对“net路径获得文件名”大致比较讲究,姐妹们都想要剖析一些“net路径获得文件名”的相关文章。那么小编也在网摘上搜集了一些有关“net路径获得文件名””的相关内容,希望看官们能喜欢,大家一起来了解一下吧!

一、查看PDF文件内容

protected void Page_Load(object sender, EventArgs e)      {           string url = Request.QueryString["url"];           Response.ContentType = "application/pdf";           Response.Clear();           Response.TransmitFile(url);           Response.End();                  }
二、下载文件到本地
protected void Page_Load(object sender, EventArgs e)      {           string url = Request.QueryString["url"];           string fileURL = HttpContext.Current.Server.MapPath("~") + url;           FileInfo fileInfo = new FileInfo(fileURL);           Response.Clear();           Response.AddHeader("content-disposition", "attachment;filename=" + Server.UrlEncode(fileInfo.Name.ToString()));           Response.AddHeader("content-length", fileInfo.Length.ToString());           Response.ContentType = "application/octet-stream";           Response.ContentEncoding = System.Text.Encoding.Default;           Response.WriteFile(fileURL);      }

标签: #net路径获得文件名