I am trying to save an image from the client side to a folder using vb.net
"" the image that has the 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.
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
<asp:FileUpload ID="FileUpload1" runat="server" />
And in your Codebehind, you can save that to a location by Calling the PostedFile.SaveAs
method
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. 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.