Reputation: 13
I want to create a functionality that allow my web application to download the file from given URL after every hour.
Should be something like this :
Thanking You, Ram Vinay Kumar
Upvotes: 0
Views: 5498
Reputation: 276
Your solution would be in 3 steps:
1. Download file from URL
Have a look at System.Net.WebClient
using (WebClient Client = new WebClient ())
{
Client.DownloadFile("http://www.abc.com/file/song/a.mpeg", "a.mpeg");
}
2. Unzip the file
In .Net 4.5, you can look at System.IO.Compression.ZipFile
string startPath = @"c:\example\start";
string zipPath = @"c:\example\result.zip";
string extractPath = @"c:\example\extract";
ZipFile.CreateFromDirectory(startPath, zipPath);
ZipFile.ExtractToDirectory(zipPath, extractPath);
Or probably look into SharpZipLib
if you want more robust solution to unzip
3. Scheduler
you can look at System.Timers
;
public void MyMethod()
{
Timer timer = new Timer();
timer.Interval = new TimeSpan(0, 15, 0).TotalMilliseconds;
timer.AutoReset = true;
timer.Elapsed += new ElapsedEventHandler(Timer_Elapsed);
timer.Enabled = true;
}
public void Timer_Elapsed(object sender, ElapsedEventArgs e)
{
//Do your stuff here
}
Combine these and code your solution.
Upvotes: 3