C# 如何使用mvc asp.net从其他服务器下载文件

C# 如何使用mvc asp.net从其他服务器下载文件,c#,asp.net-mvc,c#-4.0,C#,Asp.net Mvc,C# 4.0,如何从其他服务器下载文件并使用带有c#的mvc asp.net将其保存在我自己的服务器上?我只能阅读您的标题,但是: WebClient client = new WebClient(); client.DownloadFile("http://your-address.com/FileToDonwload.ext", "c:\PathToTheFileToCreate"); 应该做你想做的事。我只能读你的标题,不过: WebClient client = new WebClient(); c

如何从其他服务器下载文件并使用带有c#的mvc asp.net将其保存在我自己的服务器上?

我只能阅读您的标题,但是:

WebClient client = new WebClient();
client.DownloadFile("http://your-address.com/FileToDonwload.ext", "c:\PathToTheFileToCreate");

应该做你想做的事。

我只能读你的标题,不过:

WebClient client = new WebClient();
client.DownloadFile("http://your-address.com/FileToDonwload.ext", "c:\PathToTheFileToCreate");

应该做你想做的事。

我将使用System.Web.Mvc.FilePathResult并遵循以下原则:

// most controller logic ommitted
public ActionResult DownloadFile(int fileID)
{
    // in this example fileID would map to a file location in the database
    var item = _repository.GetByKey(fileID);

    // item.DocType would equal "application/msword" / "image/jpeg" etc, etc;
    return File(item.DocumentLocation, item.DocType);        
}

[edit]-ooops,刚刚意识到这只会在同一服务器/域上工作,但已留下供参考

我将使用System.Web.Mvc.FilePathResult如下所示:

// most controller logic ommitted
public ActionResult DownloadFile(int fileID)
{
    // in this example fileID would map to a file location in the database
    var item = _repository.GetByKey(fileID);

    // item.DocType would equal "application/msword" / "image/jpeg" etc, etc;
    return File(item.DocumentLocation, item.DocType);        
}

[编辑]-ooops,刚刚意识到这只适用于同一服务器/域,但已留下供参考

请使用英语;这里讲波兰语的人不多。您想如何下载该文件?您正在从Windows共享下载它吗?URL?FTP?我想从url下载它,我必须通过get-metodJust发送密码和用户名以澄清,您希望用户从运行代码的服务器下载文件,还是希望运行代码的服务器从另一台(总共)服务器下载文件?请用英语;这里讲波兰语的人不多。您想如何下载该文件?您正在从Windows共享下载它吗?URL?FTP?我想从url下载它,我必须通过get-metodJust发送密码和用户名以澄清,您是希望用户从运行代码的服务器下载文件,还是希望运行代码的服务器从另一台(总共)服务器下载文件?