Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
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
Sergey Alexandrovich Kryukov 17-Apr-13 0:57am    
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)
Sergey Alexandrovich Kryukov 17-Apr-13 1:30am    
OK. I don't want to ask what's your problem; just please see my answer.
—SA

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
 
Share this answer
 
v2
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
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900