简单页面
xiazai通过Response.WriteFile()函数将指定的文件直接写入HTTP内容输出流。该方 法实现比较简单,本例中通过函数FileDownload()实现文件的
下载,代码如下:
private void FileDownload(string FullFileName)
{
FileInfo DownloadFile = new FileInfo(FullFileName);
Response.Clear();
Response.ClearHeaders();
Response.Buffer = false;
Response.ContentType = “application/octet-stream”;
Response.AppendHeader(“Content-Disposition”, “p_w_upload;filename=” + HttpUtility.UrlEncode(DownloadFile.FullName, System.Text.Encoding.UTF8));
Response.AppendHeader(“Content-Length”, DownloadFile.Length.ToString());
Response.WriteFile(DownloadFile.FullName);
Response.Flush();
Response.End();
}
由于在代码中使用了 FileInfo 类,必须在代码的开始引用 System.IO 空间,引用代码如下所示。
using System.IO;
FileInfo 类提供创建、复制、删除、移动和打开文件的实例方法,并且帮助创建FileStream对象。其中,Length属性用来获取当前文件的大小,FullName 属性获取目录或文件的完整目录。
转载于:https://blog.51cto.com/ttsun/280692