protected void Page_Load(object sender, EventArgs e)
{
string FullFileName = "";
//ASP.NET下载文件(弹出打开保存文件对话框)
//fileURL为带路径的文件全名
//无错版:
try
{
string FileName ="";
FileName = @"UserFiles/Matytype快捷键.txt";
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
{
//文件不存在
Response.Write("File not exist");
}
}
catch
{
//打开时异常了
Response.Write("Exception occured");
}
}