0

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を使用して保存する方法があるかどうかを知りたいです。

4

2 に答える 2

1
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
于 2012-05-24T13:00:38.047 に答える
0

クライアント側から (ブラウザを介してユーザーから) ファイルをサーバー フォルダーにアップロードする場合は、FileUpload コントロールを使用する必要があります。

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

PostedFile.SaveAsコードビハインドでは、メソッドを呼び出すことでそれを場所に保存できます

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

編集 :コメントによると

インターネットからファイルをダウンロードする場合は、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
于 2012-05-24T13:04:52.233 に答える