【发布时间】:2019-04-30 13:02:21
【问题描述】:
我有一个在 IIS 上运行的项目 ASP.NET Core 2.0 MVC。 想要将数据网格中的一些信息导出到 Excel 并从网页保存到当前用户的桌面。
string fileName = "SN-export-" + DateTime.Now + ".xlsx";
Regex rgx = new Regex("[^a-zA-Z0-9 -]");
fileName = rgx.Replace(fileName, ".");
string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
string fileName2 = Path.Combine(path, fileName);
FileInfo excelFile = new FileInfo(fileName2);
excel.SaveAs(excelFile);
这在 Visual Studio 本地完美运行,但在 IIS 上发布后就不行了。 使用简单的路径字符串 path = @"C:\WINDOWS\TEMP";它将将此导出文件保存在服务器临时文件夹中,但不保存当前网页用户。 这个怎么弄?
【问题讨论】:
标签: asp.net-mvc iis path .net-core export-to-excel