ASP.NET下载文件(弹出打开保存文件对话框)

ASP.NET下载文件(弹出打开保存文件对话框) //fileURL为带路径的文件全名 System.IO.FileInfo fileInfo = new System.IO.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); 无错版: try ...{ 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 ...{ //文件不存在 }

你可能感兴趣的:(.net,asp.net,asp)