View Single Post
Old Jan 17th, 2007, 6:20 PM   #6
tristolas
Newbie
 
Join Date: Jan 2007
Posts: 6
Rep Power: 0 tristolas is on a distinguished road
For WebClient.DownloadFile Method, I don't know where to start; a console or windows application?
can I use this method within either one?

If I do windows form,
would I just replace Public Class Form1 with Public Class WebClient or do I have to edit the "meta-file" with
<ComVisibleAttribute(True)> _
Public Class WebClient
Inherits Component


Also the only way I know how to trigger the method(download file) is through a button declared as Private Sub Button1_Click()... but can I declare Public Sub DownloadFile() inside of this^ Private ButtonClick Sub ?

Then would I just stick the method inside of an incrementing loop ?
For example
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim adress As String = "http://www.contoso.com/library/homepage/images/"
        Dim number As Integer
        For number = 1 To 174
            Dim fileName As String = "ms-banner.gif" + number
            Dim fulladress As String = Nothing
            ' Create a new WebClient instance.
            Dim myWebClient As New Net.WebClient()
            ' Concatenate the domain with the Web resource filename. Because DownloadFile 
            'requires a fully qualified resource name, concatenate the domain with the Web resource file name.
            fulladress = adress + fileName
            Console.WriteLine("Downloading File ""{0}"" from ""{1}"" ......." + ControlChars.Cr + ControlChars.Cr, fileName, fulladress)
            ' The DownloadFile() method downloads the Web resource and saves it into the current file-system folder.
            myWebClient.DownloadFile(fulladress, fileName)
            Console.WriteLine("Successfully Downloaded file ""{0}"" from ""{1}""", fileName, fulladress)
            Console.WriteLine((ControlChars.Cr + "Downloaded file saved in the following file system folder:" + ControlChars.Cr + ControlChars.Tab + Application.StartupPath))
        Next

    End Sub
End Class

Is doing it through console or wget script is simpler (requires less steps) ?

Last edited by tristolas; Jan 17th, 2007 at 6:45 PM.
tristolas is offline   Reply With Quote