繁体   English   中英

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

[英]how to download file from other server using mvc asp.net

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

不过,我只能阅读您的标题:

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] -糟糕,您刚刚意识到这只能在相同的服务器/域上使用,但仅供参考

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM