Results 1 to 5 of 5

Thread: [2005] Download without popup?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,547

    [2005] Download without popup?

    how would i dl a file from the internet without the annoying ie popup?

  2. #2
    Hyperactive Member francisstokes's Avatar
    Join Date
    May 2005
    Location
    Kent, England
    Posts
    272

    Re: [2005] Download without popup?

    The popup is there for a reason. to alert the user that they are downloading something, and to select the directory to save to.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,547

    Re: [2005] Download without popup?

    Quote Originally Posted by francisstokes
    The popup is there for a reason. to alert the user that they are downloading something, and to select the directory to save to.
    ya but isnt there a way to do it besides using a webbrowser?

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,547

    Re: [2005] Download without popup?

    Quote Originally Posted by high6
    ya but isnt there a way to do it besides using a webbrowser?
    any help?

  5. #5
    Fanatic Member cpatzer's Avatar
    Join Date
    Sep 2004
    Posts
    537

    Re: [2005] Download without popup?

    This should do the trick. You will obviously need to do some editing though.

    VB Code:
    1. Imports System.Net
    2. Imports System.Web
    3.  
    4.  
    5. Public Class MyAsyncReader
    6.  
    7.     Public Event DownloadComplete()
    8.     Public Event ProgressChanged(ByVal Progress As Integer)
    9.  
    10.     Public Function DownloadFile(ByVal DownloadURL As String, ByVal LocalFile As String, ByVal CookieString As String) As Boolean
    11.         Try
    12.             'State object
    13.             Dim myStateClass As MyAsyncReaderClass = New MyAsyncReaderClass
    14.  
    15.             'Get total file size
    16.             Dim myHTTPRequest As HttpWebRequest = CType(WebRequest.Create(DownloadURL), HttpWebRequest)
    17.             'myHTTPRequest.AllowAutoRedirect = True
    18.  
    19.  
    20.             'setup proxy
    21.             If MasterForm.UseProxy Then
    22.                 Dim myProxy As New WebProxy
    23.                 myProxy.Address = New Uri("http://" + MasterForm.ProxyHost + ":" + MasterForm.ProxyPort)
    24.                 myProxy.Credentials = New NetworkCredential(MasterForm.ProxyLogin, MasterForm.ProxyPassword)
    25.                 myHTTPRequest.Proxy = myProxy
    26.             End If
    27.  
    28.             'set up cookies
    29.             myHTTPRequest.CookieContainer = New CookieContainer
    30.             myHTTPRequest.CookieContainer.SetCookies(New Uri("http://www.mydomain.com/"), CookieString)
    31.  
    32.             Dim myHTTPResponse As HttpWebResponse = CType(myHTTPRequest.GetResponse(), HttpWebResponse)
    33.  
    34.             myStateClass.TotalBytes = myHTTPResponse.ContentLength
    35.             myStateClass.SavedBytes = 0
    36.  
    37.             myHTTPResponse.Close()
    38.             myHTTPResponse = Nothing
    39.             myHTTPRequest = Nothing
    40.  
    41.             'Open URL
    42.             Dim myWebClient As System.Net.WebClient = New System.Net.WebClient
    43.             Dim myStream As System.IO.Stream = myWebClient.OpenRead(DownloadURL)
    44.  
    45.             'Open reading/writing streams
    46.             myStateClass.Writer = New System.IO.StreamWriter(LocalFile)
    47.             myStateClass.Reader = New System.IO.StreamReader(myStream)
    48.  
    49.             'Start reading asynchronously
    50.             myStateClass.Reader.BaseStream.BeginRead(myStateClass.bBuffer, 0, 4096, New AsyncCallback(AddressOf myCallBackFunction), myStateClass)
    51.             Return True
    52.         Catch ex As Exception
    53.             MessageBox.Show(ex.Message, "Error Downloading", MessageBoxButtons.OK, MessageBoxIcon.Error)
    54.             Return False
    55.         End Try
    56.     End Function
    57.  
    58.     'Async callback
    59.     Private Sub myCallBackFunction(ByVal asyncResult As IAsyncResult)
    60.  
    61.         'Get state object
    62.         Dim myStateClass As MyAsyncReaderClass = CType(asyncResult.AsyncState, MyAsyncReaderClass)
    63.         Dim bytesRead As Integer = myStateClass.Reader.BaseStream.EndRead(asyncResult)
    64.  
    65.         'Advance progress
    66.         myStateClass.SavedBytes += bytesRead
    67.         'Assuming a public progress bar named progBar with min value=0 and max value=100
    68.         MasterForm.ProgressStatusBar.progressBar.Value = Convert.ToInt32(myStateClass.SavedBytes * 100 / myStateClass.TotalBytes)
    69.         Dim DownloadedSoFar As Double = Math.Round(myStateClass.SavedBytes / 1024, 2)
    70.         Dim TotalBytes As Double = Math.Round(myStateClass.TotalBytes / 1024, 2)
    71.         MasterForm.ProgressStatusBar.Panels(1).Text = "Downloading... " + DownloadedSoFar.ToString + " KB of " + TotalBytes.ToString + " KB"
    72.  
    73.         myStateClass.Writer.BaseStream.Write(myStateClass.bBuffer, 0, bytesRead)
    74.  
    75.         If myStateClass.SavedBytes < myStateClass.TotalBytes Then
    76.             'Nope, do it again
    77.             myStateClass.Reader.BaseStream.BeginRead(myStateClass.bBuffer, 0, 4096, New AsyncCallback(AddressOf myCallBackFunction), myStateClass)
    78.         Else
    79.             'Yes, close everything
    80.             myStateClass.Writer.Close()
    81.             myStateClass.Reader.Close()
    82.             myStateClass.Writer = Nothing
    83.             myStateClass.Reader = Nothing
    84.             RaiseEvent DownloadComplete()
    85.         End If
    86.  
    87.     End Sub
    88.  
    89.     'Class to create state object
    90.     Private Class MyAsyncReaderClass
    91.  
    92.         Public TotalBytes As Integer            'Total bytes of file
    93.         Public SavedBytes As Integer            'Bytes read so far
    94.         Public Writer As System.IO.StreamWriter 'Writing stream
    95.         Public Reader As System.IO.StreamReader 'Reading stream
    96.         Public bBuffer(4096) As Byte            'Buffer
    97.  
    98.     End Class
    99.  
    100. End Class
    In life you can be sure of only two things... death and taxes. I'll take death.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width