You are on page 1of 2

Downloading file using C# - This article explains how to make simple program that will download file every

n minutes and save it to specified fold... http://www.osix.net/modules/article/?id=875

26489 total geeks with 3501 solutions


Recent challengers:
djcomidi bonus 11 - 05:44PM
djcomidi bonus 17 - 04:43PM
taurean1434 level 3 - 11:07AM

Welcome, you are an anonymous user! [register] [login] Get a yourname@osix.net email address

Articles Article viewer


C
Dot.Net
Windows Downloading file using C#
Visual Basic
Written by: Galax
Security
Miscellaneous Published by: sefo
Published on: 2007-09-30 03:21:39 Search OSI about Dot.Net. More articles by Galax.
Show/Hide...
Topic: Dot.Net viewed 17760 times send this article printer friendly

GEEK Digg this!


Rate this article :
Challenge
Bonus Levels This article explains how to mak e simple program that will download file every n minutes and save it to specified folder. So you can basically grab web cam pictures.

Geek Reverser
View Solutions
Test Centre
Mau Ke Luar Angkasa ?
Hall of Brain www.axeapollo.co.id
Hall of Bonus Tinggal Hari Ini Kesempatan Lo Bisa Pergi Ke Luar Angkasa Sob. Buruan!
Hall of
Reverse Program will download file every n minutes and save it to specified folder. So you can basically grab web cam pictures and make nice looking time line.
Geek or Freak

User's box So what information is needed?


Username: URL of picture
Where pictures are saved
Password:
Time interval

Lets make couple of TextBox and NumericUpDown control for time. Something like Start button and browse folder button is also needed. I dont like user to type paths so we disabled the folder edit box.
Forgot
password? We also needed to timer control and folderBrowserDialog. Some kind of user check input is required. We make simple test to see if there is URL and Folder boxes text. If there are we can enable start button.
New account
When user fill the form and press start button some kind feedback would be nice. So lets change the text to Stop, and start downloading file. Timer uses milliseconds so we need to convert minutes to milliseconds. When timer is started it waits specified time and then calls the tick routine. This isn't good, pressing start and wait just like local bank. So we call download
Shoutbox routine one time before we start waiting timer event.
MaxMouse
It's Friday... Lets download the file and save it. Save it with what name? Lets use time stamp. After quick search in Google we notice that default time format is 10/12/2002 10:11 PM and there is group of time formats that are near of this. Now this isnt good because we cannot use / and : charters in filenames.
That's good
enough for me! So we need to build date string. Lets use European style date dd.MM.YYYY and put dot in the time format. We dont need seconds here so we can drop them off. After quick test I noticed that filename extension is missing so computer doesnt understand picture files. Picture files can be in several formats and if user wants to download other files than pictures we need to
CodeX know the extension. Lets parse the URL to get the extension we need.
non stop lolz
here but thats After downloading couple of files I noticed that the program actually stops when the file has been downloaded. I used DownloadFile() method for this. So the program actually stops that time when file is downloaded. Wrong method call, asynchronous is magic word. So we need to use DownloadFileAsync() method.
soon to end
thanks to uni, using System;
using System.Collections.Generic;
surely the rest
using System.ComponentModel;
of the world is
using System.Data;
going good? using System.Drawing;
stabat using System.Text;
how things are using System.Windows.Forms;
going guys? using System.IO;
Here... using System.Net;
boring...
CodeX namespace TimeDL
I must be {
going wrong on public partial class Form1 : Form
the password {
bool dl = false;
lengths then,
as long as it
public Form1()
was done on {
ECB InitializeComponent();
MaxMouse }
lol... the key is
in hex (MD5: private void button2_Click(object sender, EventArgs e)
of the string {
"doit" without folderBrowserDialog1.ShowDialog();
the "'s) and is textBoxFolder.Text = folderBrowserDialog1.SelectedPath;
in lower case. }
Maybe i should
private void textBoxURL_TextChanged(object sender, EventArgs e)
have
{
submitted this if (textBoxURL.Text.Length > 0 && textBoxFolder.Text.Length > 0)
as a challenge! button1.Enabled = true;

}
Donate
Donate and help private void textBoxFolder_TextChanged(object sender, EventArgs e)
us fund new {
challenges if (textBoxURL.Text.Length > 0 && textBoxFolder.Text.Length > 0)
button1.Enabled = true;
}
Due Date: Sep 30 private void button1_Click(object sender, EventArgs e)
September {
Goal:
$40.00
if (dl == false)
Gro ss: $0.00 {
Net button1.Text = "Stop";
Balance: $0.00 timer1.Interval = Convert.ToInt32(numericUpDownInterval.Value) * 1000 * 60;
Le ft to go: $40.00 timer1_Tick(null, null);
timer1.Start();
Contributors dl = true;
}
else
{
News Feeds button1.Text = "Start";
The Register timer1.Stop();
Memory muddle dl = false;
muddies Intel"s }
Exascale ambitions }
Microsoft reissues
September patches private void timer1_Tick(object sender, EventArgs e)
after user {
complaints string stamp;
DateTime CurrTime = DateTime.Now;

1 of 2 9/15/2013 10:53 AM
Downloading file using C# - This article explains how to make simple program that will download file every n minutes and save it to specified fold... http://www.osix.net/modules/article/?id=875

Server hack heads string extension;


up the stack for a
new challenge
extension = Path.GetExtension(textBoxURL.Text);
Billio naire
engineer Ray
stamp = string.Format("{0:dd.MM.yyyy HH.mm}", CurrTime);
Dolby, stamp += extension;
80 , dies at ho me in
San Francisco try
The future o f PCIe: {
Get small, speed WebClient client = new WebClient();
up, think o utside Uri uri = new Uri(textBoxURL.Text);
the box client.DownloadFileAsync (uri, textBoxFolder.Text + "\\" + stamp);
Teen buys }
WikiLeaks catch (Exception exp)
server fo r $3 3,00 0 {
? w ith dad"s eBay
button1.Text = "Start";
account
timer1.Stop();
What"s in it for
dl = false;
server buyers now
that Intel"s Xeo n MessageBox.Show(exp.Message, "Exception");
E5 -260 0 v2 is }
here? }
Couchbase relaxes }
NoSQL derrire }
into
mo bile seats
It"s about tim e: Did you like this article? There are hundreds more.
Java update Join OSIX
includes to ol for
blocking drive-by Get Involved
exploits Challenge or Test your skills
Happy Friday the
13 th! It"s
Pro gramm ers" Day
Slashdot Comments:
Study: Our 3 D
Universe C ould flipside Cool, I just finished such an app. I'm not good at .Net stuff but it works. Here's a screenshot
Have 20 07-1 0-01
Originate d From a 13 :39:26
4D Black Ho le
Ask Slashdot: flipside btw, finished is an overstatement... ;)
Attracting 20 07-1 0-01
Developers To 14 :23:03
Abando nware?
Stephen Colbert
niazi587 Many People are developing OSIX in a superb way and i think Galax has contributed a lot.. OSIX should have rating system to encourage their participants. This article is nothing but excellent job by Galax. Thanx Galax for providing this information.
and
20 07-1 1-01 Data Entry
10 :32:16
the Monste r Truck
of Tivos
Anonymous Nice example, instead of using a textbox or a hardcoded url, how can I download files from a list of urls in a textfile or xml file? can someone point me to tutorial or something. thx
Open Source, Open 20 08-0 6-12
Wo rld 00 :27:24
How Amateurs
Destro yed the Anonymous than q
Pro fessio nal Music 20 09-0 5-02
Business 12 :09:03
US, Russia Agree
On
Plan To Dispose of
Syria"s C hemical
Bursa Blackberry Murah
Weapons
The Boy Genius of
www.berniaga.com/mobile
Ulan Bator
Semua Tipe dengan Harga Bersaing. Situs Jual/Beli Blackberry Lengkap
Japan Controls
Ro cket Launch
With
Just 8 People and
2
Enter the Inner Sanctum
Laptops
45 % of U.S. Jobs
www.secretsanctuaries.com
Vulnerable To Ultimate insiders' guide to secret societies, Templars, occult sites
Autom ation
Dogs Lo ve Ro bots,
Prefer Hum ans Anonymously add a comment: (or register here)
(registration is really fast and we send you no spam)

BB Code is enabled.
Captcha Number:

Batch Files Password Cracker Windows Password Password Cracking

Blogs: (Peo ple who have posted blogs on this subject..)

bb ASP.NET RadioButton GroupName when inside a Repeater on Sun 10th Jun 8am
I was thankful on finding this nugget of code, which makes the groupname work out when slamming in radiobuttons in an asp.net repeater. http://www.codeguru.com/csharp/csharp/cs _controls/custom/article.php/c12371/

Your Ad Here

Copyright Open Source Institute, 2006

2 of 2 9/15/2013 10:53 AM

You might also like