Click here to Skip to main content
14,641,699 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi,i am working on windows form .How to download text file using vb.net code on button click events
Posted
Updated 16-Apr-13 18:52pm
v2
Comments
   
Ever heard of separation of concerns? How Forms and click can be related to downloading?
OK, download from where? by what protocol? What did you try so far?
—SA
shashank 1068 17-Apr-13 1:23am
   
i have tried this code:

Dim remoteUri As String = "http://www.contoso.com/library/homepage/images/"
Dim fileName As String = "ms-banner.gif", myStringWebResource As String = Nothing
' Create a new WebClient instance.
Dim myWebClient As New WebClient()
' Concatenate the domain with the Web resource filename.
myStringWebResource = remoteUri & fileName
Console.WriteLine("Downloading File ""{0}"" from ""{1}"" ......." & vbLf & vbLf, fileName, myStringWebResource)
' Download the Web resource and save it into the current filesystem folder.
myWebClient.DownloadFile(myStringWebResource, fileName)
Console.WriteLine("Successfully Downloaded File ""{0}"" from ""{1}""", fileName, myStringWebResource)
Console.WriteLine(vbLf & "Downloaded file saved in the following file system folder:" & vbLf & vbTab + Application.StartupPath)
   
OK. I don't want to ask what's your problem; just please see my answer.
—SA
Rate this:
Please Sign up or sign in to vote.

Solution 2

MSDN Info about WebClient.DownloadFile

<quote>"Downloads the resource with the specified URI to a local file."

Coding this:

Friend Sub Button_Click(ByVal sender as Object, ByVal e as EventArgs) Handles Button.click
    Dim wc as System.Net.WebClient
    Dim Localfile as String = "PathOfLocalFile.ext";
    Dim Remotefile as String = "UrlOfRemoteFile.ext";

    wc.DownloadFile(RemoteFile, LocalFile)

End Sub
   
v2
Rate this:
Please Sign up or sign in to vote.

Solution 1

You can use my complete but short downloading application as a sample. I provided full source code in my past answer:
how to download a file from internet[^].

See also my past answers:
FTP: Download Files[^],
how to download a file from the server in Asp.net 2.0[^].

—SA
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100