繁体   English   中英

将图像保存到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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM