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" />

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

还有,我想知道是否有办法 使用ID来保存 因为我可能有一个以上的图像 需要保存。

最佳回答

如果您想要从客户端上传文件到服务器文件夹( 从用户通过浏览器从用户上), 您需要使用 FileUpload 控制

<asp:FileUpload ID="FileUpload1" runat="server" />

在您的编码后面, 您可以调用 < code> PostedFile. saveAs 方法, 保存到一个位置

    If FileUpload1.HasFile Then
        somefileNameWithExtension="file.pdf"   Replace this with a a valid file name
        FileUpload1.PostedFile.SaveAs(somefileNameWithExtension)
    End If

<强 > EDIT :根据评论

如果您想要从互联网下载文件, 您可以使用 WebClient 类下载工具方法进行下载。 这里举一个例子 。

    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
问题回答
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




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签