我正在尝试从我的服务器下载一个文件,我这样做:
var client = new WebClient();
client.DownloadFile(@"C:\Files\project\result.xlsx", "download.xlsx");例外情况是:
2015-01-27 13:08:13,686 [55] ERROR GeneralLogger - System.Net.WebException: An exception occurred during a WebClient request. ---> System.UnauthorizedAccessException: Access to the path 'C:\Program Files (x86)\IIS Express\download.xlsx' is denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)
at System.Net.WebClient.DownloadFile(Uri address, String fileName)
--- End of inner exception stack trace ---
at System.Net.WebClient.DownloadFile(Uri address, String fileName)
at System.Net.WebClient.DownloadFile(String address, String fileName)
at EmailTemplates.Classes.ExcelUtil.CreateNewExcelFile(String variables) in 我从未使用过路径C:\Program Files (x86)\IIS Express\download.xlsx可能是默认的或类似的东西。我希望像在下载中单击任何页面时一样,将该文件下载(我这样做是因为我在同一个函数中创建了该文件)
谢谢。
发布于 2015-01-27 13:16:56
我想你误解了DownloadFile的工作。它不会将文件发送给您的web应用程序的客户。它从服务器下载一个文件。因为您没有指定任何URL,所以我认为这是您的错误。
研究如何发送文件作为对HTTP请求的响应。我会搜索"ASP.NET下载文件“。
https://stackoverflow.com/questions/28171414
复制相似问题