如何在Asp.net中的文件夹中保存图像控制图像

我知道如何使用saveas方法使用fileupload控件将图像保存到文件夹。 但我从图像控件中取出一个图像并将其保存到文件而不使用fileupload控件将其保存在文件夹中。

string filepath = img1.ImageUrl; using (WebClient client = new WebClient()) { client.DownloadFile(filepath,Server.MapPath("~/Image/apple.jpg")); } 

你知道图像路径吗? 您可以从图像控件获取图像路径,然后在代码中下载图像:

从.NET / C#站点下载图像

 using(WebClient client = new WebClient()) { client.DownloadFile("http://www.example.com/image.jpg", localFilename); } 

首先获取图像的URL,然后使用webclient,您可以将文件保存在文件夹中

 string filepath = img1.ImageUrl; using (WebClient client = new WebClient()) { client.DownloadFile(filepath,Server.MapPath("~/Image/apple.jpg")); } 

这将使用ImageName apple保存图像文件夹中的图像…