FileInfo fileInfo = new FileInfo(filePath); //实例化方法
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.AddHeader("Content-Disposition", "attachment;filename=" + pdfpath); //文件描述信息
Response.AddHeader("Content-Length", fileInfo.Length.ToString()); //文件长度
Response.AddHeader("Content-Transfer-Encoding", "binary");
Response.ContentType = "application/octet-stream";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
Response.WriteFile(fileInfo.FullName);
Response.Flush();
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.AddHeader("Content-Disposition", "attachment;filename=" + pdfpath); //文件描述信息
Response.AddHeader("Content-Length", fileInfo.Length.ToString()); //文件长度
Response.AddHeader("Content-Transfer-Encoding", "binary");
Response.ContentType = "application/octet-stream";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
Response.WriteFile(fileInfo.FullName);
Response.Flush();
Response.End();
这里的filepath 是项目中一个文件路径, 通过该文件路径直接下载