我试图使用下面的代码,允许用户下载位于本地服务器上的excel:
FileInfo dest_file= new FileInfo(filename);
Response.ClearContent();
Response.ContentType = "Excel/xls";
Response.AddHeader("Content-Disposition", string.Format("attachment; filename = {0}", filename));
Response.AddHeader("Content-Length", dest_file.Length.toString());
Response.TransmitFile(filename);
Response.End();但是,在发布解决方案后,下载文件将导致网络失败。知道我怎么解决这个问题吗?
请注意,当试图通过目录浏览访问该文件时,该文件将成功下载。
发布于 2019-09-20 07:40:18
似乎您使用了无效的内容类型。
对于xlsx,请使用以下命令
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"用于xls
Response.ContentType = "application/vnd.ms-excel"https://stackoverflow.com/questions/58023819
复制相似问题