Upload/Download Files

Use this board to post your code snippets - tips and tricks
25 posts Page 1 of 3
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4392
Joined: Tue Aug 04, 2009 1:47 am

Upload/Download Files
CodenStuff
Hello,

This snip will show you the simple way of Downloading and Uploading files to/from a website.

First you need to have 2 imports at the top of your code:
Code: Select all
Imports System.Net
Imports System.IO
Then use the following codes to do the corresponding action.

Download a file:
Code: Select all
My.Computer.Network.DownloadFile("http://www.WEBSITE.com/NameOfFile.ext", "SaveAs.ext")

Uploading a file:
Code: Select all
My.Computer.Network.UploadFile("FileToUpload.ext", "ftp://www.WEBSITE.com/StoreFileAs.ext", "USERNAME", "PASSWORD", True, 10, FileIO.UICancelOption.DoNothing)

And thats all you need to do. Simple and easy.

Happy Coding.
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
User avatar
Martin
Supreme VIP
Supreme VIP
Posts: 369
Joined: Sat Aug 01, 2009 12:26 pm

Re: Upload/Download Files
Martin
This Code Works Great Vhite My New Program
Image
User avatar
Nery
Co-Admin Moderator
Co-Admin Moderator
Posts: 1117
Joined: Mon Sep 07, 2009 8:11 pm

Re: Upload/Download Files
Nery
I used your snippet to successfully produce a Youtube Video Downloader ^^

Guess what... Both uploading and downloading videos works! :D
User avatar
CodemaN
VIP Access - Denied
VIP Access - Denied
Posts: 74
Joined: Fri Sep 18, 2009 3:18 pm

Re: Upload/Download Files
CodemaN
thanks man great job
User avatar
Martin
Supreme VIP
Supreme VIP
Posts: 369
Joined: Sat Aug 01, 2009 12:26 pm

Re: Upload/Download Files
Martin
how did you make a youtube video uploder?

martin64 :D
Image
User avatar
Nery
Co-Admin Moderator
Co-Admin Moderator
Posts: 1117
Joined: Mon Sep 07, 2009 8:11 pm

Re: Upload/Download Files
Nery
Not uploader, I said DOWNLOADER ^^

Well, since youtube downloads itself the videos for each time you see them you can use the feed you're receiving from youtube to save the file in your desktop instead of making a temporary file in your internet browser's cookies folder.
Last edited by Nery on Tue Nov 10, 2009 10:30 am, edited 1 time in total.
User avatar
Neki
Top Poster
Top Poster
Posts: 96
Joined: Sun Oct 11, 2009 10:12 am

Re: Upload/Download Files
Neki
Great snippet! I like it!
GoodGuy17
Coding God
Coding God
Posts: 1610
Joined: Mon Sep 07, 2009 12:25 am

Re: Upload/Download Files
GoodGuy17
I don't get this part:
My.Computer.Network.DownloadFile("http://www.WEBSITE.com/NameOfFile.ext", ">>SaveAs.ext<<")
What should I change SaveAs.ext to? .exe? or what? Give me an example please.
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4392
Joined: Tue Aug 04, 2009 1:47 am

Re: Upload/Download Files
CodenStuff
Hello,

Thats the name of the file you want to save it as on your computer. For example if I wanted to download a file from the website called "Application.zip" and I wanted to save it on my computer as "MyApp.zip" I would use the code like this:
Code: Select all
My.Computer.Network.DownloadFile("http://www.WEBSITE.com/Application.zip", "MyApp.zip")
So the first part is the URL and name of the file you want to download. The second part is what you want to save the file as when its downloaded.

Hope that helps cooll;
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
GoodGuy17
Coding God
Coding God
Posts: 1610
Joined: Mon Sep 07, 2009 12:25 am

Re: Upload/Download Files
GoodGuy17
Thanks,
But the problem NOW is, say my code is this:
My.Computer.Network.DownloadFile(TextBox1.Text, ">>>MyApp.zip<<<")
How can I make my program figure out what the extension is?
I think I have an IDEA of what to do:
My.Computer.Network.DownloadFile(TextBox1.Text, TextBox2.Text)
And make the user type what they want to save it as(the name) AND the extension at the end?
25 posts Page 1 of 3
Return to “Quick Snips”