我需要实现点击按钮打开一个另存为的选择路径的对话框
代码如下
// 要下载的文件全名
string FullFileName = Server.MapPath(@"/Excel/myExcel.xlsx"); //FileName--要下载的文件名
// 下载文件
System.IO.FileInfo DownloadFile = new System.IO.FileInfo(FullFileName);
if (DownloadFile.Exists)
{
Response.Clear();
Response.ClearHeaders();
Response.Buffer = false;
// 设置内容类型 (https://blog.csdn.net/qwlovedzm/article/details/7247803)
// 链接内有文件后缀匹配赋值给ContentType
Response.ContentType = "application/vnd.ms-excel";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(DownloadFile.Name, System.Text.Encoding.ASCII));
Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());
Response.WriteFile(DownloadFile.FullName);
Response.Flush();
Response.End();
}
else
{
Response.Write("<scrpit>alert('导出失败')</scrpit>");
}
我这个代码是可以保存的,但是并不能够打开另存为的对话框