开发者

Download a file from any given URL and save it to my Machine with ASP.NET

Case: I need to feed my application a URL from any location on the internet. At the other end of the URL will be a file of some sorts. A picture/video/document and I need to save this item to my server automatically without a 'save-as' dialog box.

This needs to be done in ASP.NET.

Im having trouble on how to actually grab that file with asp.net after feeding开发者_如何学C it a URL... Any help would be great!

Thanks all


I'd check out the System.Net.WebClient class. The DownloadFile method should do the trick for you.

using (WebClient wc = new WebClient())
{
    wc.DownloadFile(myUrl, myLocalFileName);
}

Just make sure that the user that your web app is running as has permissions to save the file or you'll have problems.


You can use webclient or httpwebrequest. Webclient is probably easier for what you want to do.

WebClient wc = new WebClient();

wc.DownloadFile(downloadURL.Text, savePath.Text);


http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜