Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 05-06-2009
Member
 
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.
Reply With Quote
  #2  
Old 05-06-2009
Member
 
Join Date: May 2008
Posts: 2,293
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
Reply With Quote
  #3  
Old 05-06-2009
Member
 
Join Date: Oct 2005
Posts: 2,389
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/")
Reply With Quote
  #4  
Old 05-06-2009
Member
 
Join Date: May 2008
Posts: 2,383
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


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


All times are GMT +5.5. The time now is 01:43 AM.