如何从网址保存图片?

时间:2022-10-30 23:45:22

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#

I am not very good with IO stuff, hope someone can help me out :)

我对IO的东西不太好,希望有人可以帮助我:)

1 个解决方案

#1


6  

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应用程序中,则需要确保运行应用程序的身份/帐户,有权将文件写入文件系统。

#1


6  

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应用程序中,则需要确保运行应用程序的身份/帐户,有权将文件写入文件系统。