Results 1 to 4 of 4

Thread: Download and upload files via vb.net

  1. #1
    Join Date
    Jan 2009
    Posts
    46

    Download and upload files via vb.net

    Hi,
    I am working on a project based on vb.net. I want to refer some source code to download and upload file via vb.net. Is it also possible to the ping the network just to ensure the flow of traffic of any website. The uploading is also an issue here. I just want a reference material in order to avoid any mistakes. I heard there are multiple third party tools which can do the job instead of going under along scripting process.

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    Re: Download and upload files via vb.net

    I will provide a very simple program that will teach your how to download files from the website and save them. It uses to classes the first one is HttpWebRequest and the second one is HttpWebRequest to request and retrieve the requested file. The data is read into a buffer. In order to save the file on the disk the FileStream class is used. We will take an example of a image file. Like image.png. Normally a loop is required to read and keep the track how many bytes have been read to download and read the file. Till the time buffer is not 0 bytes the loop will continue till the end of stream. The size of buffer must be enough large to hold the data. The source code for it is as follows.
    Code:
    Imports System.IO
    Imports System.Net
    Imports System.Text
    Class WebRetrieve
    Public Shared Sub Main()
    Dim wr As HttpWebRequest = CType(WebRequestFactory.Create("http://www.samplewebsite.com/image.png"), HttpWebRequest)
    Dim ws As HttpWebResponse = CType(wr.GetResponse(), HttpWebResponse)
    Dim str As Stream = ws.GetResponseStream()
    Dim inBuf(100000) As Byte
    Dim bytesToRead As Integer = CInt(inBuf.Length)
    Dim bytesRead As Integer = 0
    While bytesToRead > 0
    Dim n As Integer = str.Read(inBuf, bytesRead, bytesToRead)
    If n = 0 Then
    Exit While
    End If
    bytesRead += n
    bytesToRead -= n
    End While
    Dim fstr As New FileStream("image.png", FileMode.OpenOrCreate, FileAccess.Write)
    fstr.Write(inBuf, 0, bytesRead)
    str.Close()
    fstr.Close()
    End Sub 'Main
    End Class 'WebRetrieve

  3. #3
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Download and upload files via vb.net

    The below code is an sample code which refers to ping, upload and download a file via vb.net. You can refer it and try it out. It is an error free code. As it just a sample you can add more of your information and see the result. It is an very simple and easy to understand.
    Code:
    	If My.Computer.Network.Ping("www.anywebsite.com", 1000) Then
      		MsgBox("Server pinged successfully.")
    	Else
      		MsgBox("Ping request timed out.")
    	End If
    
    	My.Computer.Network.DownloadFile _
        	("http://www.anywebsite.com/downloads/anyfile.txt", _
        	"C:\Documents\anyfile.txt")
    
    	My.Computer.Network.UploadFile( _
    	"C:\Documents\anyfile.txt", _
    	"http://www.anywebsite.com/uploads/")

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    Re: Download and upload files via vb.net

    You right about the third party tools which can be used to work with your issue. They are called File Upload and Download components. They are ready made configured to tool which extract and put files on the web server. Some them I listing below with there features.
    1. Telerik RadControls - It is for asp.net which comes with 27 major and 35 helper controls. It help to boast a well designed architecture and cab support.
    2. PowerWEB File Upload - It is an better file uploading functionality which makes your work more easier.It gives and interactive option of automatic upload progress and cancellation during the upload process.
    3. Aurigma File Downloader - Just by few clicks download multiple files from yout site. The click button is integrated to your HTML page and select destination folder and starts download.

Similar Threads

  1. Why can’t we upload 2 GB files on Nokia N8?
    By Vicky Woodley in forum Portable Devices
    Replies: 4
    Last Post: 29-11-2010, 09:19 AM
  2. How to Upload Multiple Files in PHP?
    By SKREECH in forum Software Development
    Replies: 5
    Last Post: 03-03-2010, 04:20 AM
  3. Can't upload files on any website
    By Dhiresh in forum Technology & Internet
    Replies: 3
    Last Post: 22-10-2009, 10:31 PM
  4. Upload Files in ASP.NET
    By Ariadne in forum Software Development
    Replies: 3
    Last Post: 15-01-2009, 07:05 PM
  5. Upload files to megaupload
    By goatape in forum Technology & Internet
    Replies: 2
    Last Post: 06-10-2008, 12:27 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,710,834,926.50886 seconds with 16 queries