/// <summary>
/// 保存文件对话框
/// </summary>
/// <param name="FilePath">要保存的文件全路径</param>
public static void FileSaveDialogBox(string FilePath)
{
string filename = System.IO.Path.GetFileName(FilePath);
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "application/octet-stream";
//这里的filename可以输出时自定义,不一定用原来的.
HttpContext.Current.Response.AppendHeader("Content-Disposition", "p_w_upload;filename=" + filename);
HttpContext.Current.Response.TransmitFile(FilePath);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.Close();
}
转载于:https://blog.51cto.com/lightweight/522397
本文介绍了一个简单的ASP.NET文件下载功能实现方法。通过使用HttpResponse对象,可以将指定路径下的文件发送到客户端进行下载。该示例代码展示了如何设置响应头以触发文件下载对话框,并实现了文件的实际传输。
211

被折叠的 条评论
为什么被折叠?



