![](/img/trans.png)
[英]How to store images in a list from image folder and passing it to image src in (asp.net| vb.net)
[英]Save images to folder in VB.net
我正在嘗試使用vb.net從客戶端將圖像保存到文件夾
“”具有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" />
這只是我要保存圖像的位置:我沒有使用此代碼運行或嘗試任何操作,我只是想知道如何在服務器端執行此操作
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
另外,我想知道是否有一種方法可以使用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
如果要從客戶端(通過瀏覽器從用戶)將文件上傳到服務器文件夾,則需要使用FileUpload控件
<asp:FileUpload ID="FileUpload1" runat="server" />
在您的Codebehind中,可以通過調用PostedFile.SaveAs
方法將其保存到某個位置。
If FileUpload1.HasFile Then
somefileNameWithExtension="file.pdf" ' Replace this with a a valid file name
FileUpload1.PostedFile.SaveAs(somefileNameWithExtension)
End If
編輯 :根據評論
如果要從Internet下載文件,可以使用WebClient類DownloadFile方法來完成。 這是一個例子。
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.