更新时间:2023-01-22 11:19:41
使用 WebClient.DownloadFile [ ^ ]方法。Quote:DownloadFile方法从address参数中指定的URI下载到本地文件数据。此方法在下载资源时阻止。要下载资源并在等待服务器响应时继续执行,请使用DownloadFileAsync方法之一。
本文应该有所帮助:
http://***.com/questions/295538/how-to-provide-user-name-and-password-when-connecting-to-a-network-share [ ^
My Code:
FileInfo fileinfo = new FileInfo(@"\\10.16.20.70\website.com\wwwroot\im_online.png"); Response.Clear(); Response.ClearHeaders(); Response.ClearContent(); Response.AppendHeader("Content-Disposition", "attachment; filename =im_online.png "); Response.AppendHeader("Content-Length", fileinfo.Length.ToString()); Response.ContentType = "application/download"; Response.WriteFile(fileinfo.FullName); Response.Flush(); Response.Close(); Response.End();
Error:
Logon failure: unknown user name or bad password.
How to set username and password for my remote server to download the file in it?.
Use the WebClient.DownloadFile[^] method.Quote:The DownloadFile method downloads to a local file data from the URI specified by in the address parameter. This method blocks while downloading the resource. To download a resource and continue executing while waiting for the server's response, use one of the DownloadFileAsync methods.
This article should help:
http://***.com/questions/295538/how-to-provide-user-name-and-password-when-connecting-to-a-network-share[^]