[英]Save images to folder in VB.net
I am trying to save an image from the client side to a folder using vb.net 我正在尝试使用vb.net从客户端将图像保存到文件夹
"" the image that has the myImage ID "" “”具有myImage ID的图像“”
<asp:Image runat="server" ID="myImage" ImageUrl="http://www.govcomm.harris.com/images/1F-81-imageLinks650a.jpg" />
<asp:Image runat="server" ID="myImage2" ImageUrl="http://www.govcomm.harris.com/images/2F-81-imageLinks650b.jpg" />
this is just the location where i want to save my image : i haven't run or try any thing with this code , i am just wondering how to do this this location is on the server side 这只是我要保存图像的位置:我没有使用此代码运行或尝试任何操作,我只是想知道如何在服务器端执行此操作
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim saveLocation As String = Server.MapPath("PDFs")
End Sub
Also, I would like to know if there is a way to use the id to save since i might have more than one image to be saved. 另外,我想知道是否有一种方法可以使用id保存,因为我可能要保存多个图像。
Try this one.....
import System.Net
Dim filepath As String = Server.MapPath(myImage.ImageUrl)
Using client As New WebClient()
client.DownloadFile(filepath, Server.MapPath("Specify the path where you want to store+imagename")) //------For example client.DownloadFile(filepath,Server.MapPath("~/Image/282.gif"))
End Using
If you want to upload a file from the client side (from the user via browser) to the server folder, you need to user the FileUpload control 如果要从客户端(通过浏览器从用户)将文件上传到服务器文件夹,则需要使用FileUpload控件
<asp:FileUpload ID="FileUpload1" runat="server" />
And in your Codebehind, you can save that to a location by Calling the PostedFile.SaveAs
method 在您的Codebehind中,可以通过调用PostedFile.SaveAs
方法将其保存到某个位置。
If FileUpload1.HasFile Then
somefileNameWithExtension="file.pdf" ' Replace this with a a valid file name
FileUpload1.PostedFile.SaveAs(somefileNameWithExtension)
End If
EDIT : As per the comment 编辑 :根据评论
If you want to download a file from the internet, you can do it with the WebClient classes DownloadFile method. 如果要从Internet下载文件,可以使用WebClient类DownloadFile方法来完成。 Here is an example. 这是一个例子。
Using webClient As New WebClient()
Dim targrtFileName = "D:\\myfile.png" '
Dim sourceFile = "http://converter.telerik.com/App_Themes/images/ccHead.png"
'read the Source of your image control and replace in sourceFile variable.
webClient.DownloadFile(sourceFile , targrtFileName)
End Using
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.