none
HttpWebRequest progressbar. RRS feed

  • Question

  • Can someone give me an example of tracking HttpWebRequest's progress with progressbar?
    • Moved by Liliane Teng Tuesday, June 7, 2011 8:01 AM (From:Visual Basic General)
    • Moved by Martin_XieModerator Tuesday, June 7, 2011 8:25 AM Move back. (From:Off-Topic Posts (Do Not Post Here))
    Monday, May 23, 2011 9:19 AM

Answers

  • http://www.codeproject.com/KB/vb/downloadFileswProgressbar.aspx

    http://www.codeproject.com/KB/aspnet/FlashUpload.aspx

    kindly have a look at the samples provided in the above link

    Regards,

    Narendran Ponpandiyan

    • Marked as answer by Liliane Teng Wednesday, June 8, 2011 2:07 AM
    Tuesday, June 7, 2011 10:13 AM
  • Hello,

    You can build in a progressbar in the code of a network stream. (while loop)

    My idea is You have the response.ContentLength at first. The formular is:

    progressBar1.Value =  total * 100 / len 

    progressBar1.Maximum = 100

    progressBar1.Minimum = 0


    best regards Ellen

     
     Dim buffer(1000) As Byte
     Dim read, total As Integer
     Try
      Dim request As HttpWebRequest = HttpWebRequest.Create(lUrl)
      request.Credentials = New NetworkCredential("admin", "1234")
      request.Timeout = 10000
    
      Dim response As HttpWebResponse = request.GetResponse()
      If response.StatusCode = HttpStatusCode.OK Then
    
      Dim sr As Stream = response.GetResponseStream
      Dim len As Integer = response.ContentLength
      Dim type As String = response.ContentType
    
      read = 1
      While read > 0
       read = sr.Read(buffer, total, 1000)
       total += read
       ReDim Preserve buffer(1000 + total)
    	  '		
       ' here You can realize a progressbar
       ' by calculating len and total
       '
      End While
      sr.Close()
    
    
      'Debug.Print("total: {0} read: {1}", total, read)
    
      Else
    
      MsgBox(String.Format("Server returned: {0} {1}", _
        response.StatusCode, response.StatusDescription))
    
      End If
    
    
     Catch ex As Exception
      MsgBox(ex.ToString)
     End Try
    
    
    Ich benutze/ I'm using VB2008 & VB2010


    • Edited by Ellen Ramcke Tuesday, June 7, 2011 3:50 PM formular now correct
    • Marked as answer by Liliane Teng Wednesday, June 8, 2011 2:08 AM
    Tuesday, June 7, 2011 9:45 AM

All replies

  • Hi,

    You should asked in the Asp.Net forum.

    Look here: http://forums.asp.net/

    You can find more about the HttpWebRequest in the HttpWebRequest Class, look here:

    http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx

     

    Monday, May 23, 2011 9:45 AM
  • Hello,

    You can build in a progressbar in the code of a network stream. (while loop)

    My idea is You have the response.ContentLength at first. The formular is:

    progressBar1.Value =  total * 100 / len 

    progressBar1.Maximum = 100

    progressBar1.Minimum = 0


    best regards Ellen

     
     Dim buffer(1000) As Byte
     Dim read, total As Integer
     Try
      Dim request As HttpWebRequest = HttpWebRequest.Create(lUrl)
      request.Credentials = New NetworkCredential("admin", "1234")
      request.Timeout = 10000
    
      Dim response As HttpWebResponse = request.GetResponse()
      If response.StatusCode = HttpStatusCode.OK Then
    
      Dim sr As Stream = response.GetResponseStream
      Dim len As Integer = response.ContentLength
      Dim type As String = response.ContentType
    
      read = 1
      While read > 0
       read = sr.Read(buffer, total, 1000)
       total += read
       ReDim Preserve buffer(1000 + total)
    	  '		
       ' here You can realize a progressbar
       ' by calculating len and total
       '
      End While
      sr.Close()
    
    
      'Debug.Print("total: {0} read: {1}", total, read)
    
      Else
    
      MsgBox(String.Format("Server returned: {0} {1}", _
        response.StatusCode, response.StatusDescription))
    
      End If
    
    
     Catch ex As Exception
      MsgBox(ex.ToString)
     End Try
    
    
    Ich benutze/ I'm using VB2008 & VB2010


    • Edited by Ellen Ramcke Tuesday, June 7, 2011 3:50 PM formular now correct
    • Marked as answer by Liliane Teng Wednesday, June 8, 2011 2:08 AM
    Tuesday, June 7, 2011 9:45 AM
  • http://www.codeproject.com/KB/vb/downloadFileswProgressbar.aspx

    http://www.codeproject.com/KB/aspnet/FlashUpload.aspx

    kindly have a look at the samples provided in the above link

    Regards,

    Narendran Ponpandiyan

    • Marked as answer by Liliane Teng Wednesday, June 8, 2011 2:07 AM
    Tuesday, June 7, 2011 10:13 AM
  • http://www.codeproject.com/KB/vb/downloadFileswProgressbar.aspx

    http://www.codeproject.com/KB/aspnet/FlashUpload.aspx

    kindly have a look at the samples provided in the above link

    Regards,

    Narendran Ponpandiyan


    Hi

    Narendran Ponpandiyan

    very good sample

    Ellen


    Ich benutze/ I'm using VB2008 & VB2010
    Tuesday, June 7, 2011 7:54 PM
  • Thank you for your answer, but why is my Content Length always -1?
    Wednesday, June 8, 2011 9:29 PM
  • Anyone? When I try this code, Content Length is always -1.

     

     Dim Request As HttpWebRequest = DirectCast(WebRequest.Create("http://www.google.com"), HttpWebRequest)
        Dim Response As HttpWebResponse = Request.GetResponse()
        Dim Length As Long = response.ContentLength
        MsgBox(Length)
    

    Thursday, June 9, 2011 11:47 AM