简体   繁体   English

如何从网址保存图片?

[英]How do I save an Image from an url?

How do I take an image from an url and save it locally? 如何从网址中获取图片并将其保存在本地?

http://someurl.com/imagename.jpg -> c:\\apppath\\imgfolder http://someurl.com/imagename.jpg- > c:\\ apppath \\ imgfolder

ASP.NET C# ASP.NET C#

I am not very good with IO stuff, hope someone can help me out :) 我对IO的东西不是很好,希望有人可以帮我:)

Try this. 尝试这个。

System.Net.WebClient wc = new System.Net.WebClient();

wc.DownloadFile("http://www.domin.com/picture.jpg", @"C:\Temp\picture.jpg");

Since you've tagged this with ASP.NET, it's worth pointing out that if you put this code in your ASP.NET Website/Web Application, you'll need to make sure the the Identity/Account that your application is running as, has permission to write the file to the file system. 由于已使用ASP.NET对此进行了标记,因此需要指出的是,如果将此代码放入ASP.NET网站/ Web应用程序中,则需要确保应用程序运行时所使用的身份/帐户,有权将文件写入文件系统。

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

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