为远程服务器中的文件创建下载链接? [英] Creating Download Link for a file in remote server?
本文介绍了为远程服务器中的文件创建下载链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码:
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();
错误:
登录失败:未知用户名或密码错误。
如何为我的远程服务器设置用户名和密码以下载文件?。
解决方案
使用 WebClient.DownloadFile [ ^ ]方法。
Quote:DownloadFile方法从address参数中指定的URI下载到本地文件数据。此方法在下载资源时阻止。要下载资源并在等待服务器响应时继续执行,请使用DownloadFileAsync方法之一。
本文应该有所帮助:
http://stackoverflow.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://stackoverflow.com/questions/295538/how-to-provide-user-name-and-password-when-connecting-to-a-network-share[^]
这篇关于为远程服务器中的文件创建下载链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文