My.Computer.Network.DownloadFile error. Help!

ckaiser

New member
Joined
Jan 27, 2011
Messages
2
Location
Florida
Programming Experience
Beginner
Hello everyone. I'm brand new, and need a little guidance. I'm using Visual Studio Express 2008 and learning.

I set out to create a specific type of application, really simple dedicated browser type of application using the webbrowser control and I've run into a snag.

I have tried to simulate the "save as" right click menu item for the webbrowser control, to function like the IE one and after a lot of searching and research I have succeeded pretty much in making a right click menu that will bring up the SaveFileDialog. My goal is to be able to save an image from a web page when that is the only option supplied by an online graphic generator for saving rendered images.

It works, and I can save whatever image my mouse pointer is over, but I'm having a problem when I click the cancel button or the x button to close the dialog.

Here is the error I'm getting when running the app in debug:


Argument cannot be Nothing. Parameter name: destinationFileName

on this line :

My.Computer.Network.DownloadFile(ImageSource, SavePath)

Here is my code for the context menu button I'm using for the save function :

VB.NET:
Private Sub SaveImageToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveImageToolStripMenuItem.Click
        Dim ImageSource As String = Ele.GetAttribute("src")
        Dim sv As New SaveFileDialog
        Try
            sv.Filter = "Jpeg(*.Jpeg)|*.jpeg|Jpg(*.Jpg)|*.Jpg|Png(*.Png)|*.png|Bmp(*.Bmp)|*.Bmp|Gif(*.Gif)|*.Gif"
            sv.ShowDialog()
            Dim SavePath As String = sv.FileName
            If System.IO.File.Exists(SavePath) Then
                MessageBox.Show("File already exits. Please save image again with another file name")
            Else

                My.Computer.Network.DownloadFile(ImageSource, SavePath)

            End If
           
        Catch ex As Exception
            

        End Try
    End Sub

Edit :
From what I can understand about this, is that if the dialog box is canceled, then My.Computer.Network.DownloadFile(ImageSource, SavePath) can't get the parameters, and that's why I get the error message.

That would tell me that I need to detect if the dialog is canceled, and if it is, then not execute the My.Computer.Network.DownloadFile(ImageSource, SavePath) part of the code, and allow the dialog box to close, but I don't know how to do that.

Any ideas? I'm new, but I've been researching my head off, and haven't yet pieced it together. Thanks.

Craig
 
Last edited:
Back
Top