473,387 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Webclient.Downloadfile to get the latest version

Hi,

I am using the webclient.downloadfile() method to download a file from
a remote web server to the local harddrive.

public CopyFile(string sSrcPath, string sDestPath)
{
WebClient oClient = new WebClient();
oClient.DownloadFile(sSrcPath,sDestPath);
}

Is there anyway i can determine that if the local file exists already
and the file from the web server is newer download it, otherwise
leave it? (Conditional Get) tried accessing the Headers property and
setting the "if-modified-since" to that of the localfiles last write
time, but i get an exception that i can't modify that header property.

try
{
FileInfo oFileInfo = new FileInfo(sDestPath);
if(oFileInfo.Exists)
{
DateTime t = oFileInfo.LastWriteTime.ToUniversalTime();
oClient.Headers["if-modified-since"] = t.ToString("r");
}

oClient.DownloadFile(sSrcPath,sDestPath);
}
Any ideas greatly appreciated.
Cheers.
Jul 21 '05 #1
1 4207
James Write wrote:
Hi,

I am using the webclient.downloadfile() method to download a file from
a remote web server to the local harddrive.

public CopyFile(string sSrcPath, string sDestPath)
{
WebClient oClient = new WebClient();
oClient.DownloadFile(sSrcPath,sDestPath);
}

Is there anyway i can determine that if the local file exists already
and the file from the web server is newer download it, otherwise
leave it? (Conditional Get) tried accessing the Headers property and
setting the "if-modified-since" to that of the localfiles last write
time, but i get an exception that i can't modify that header property.


There are a couple of HTTP headers that cannot be set using the Headers
property. These headers are either set implicitly (e.g. Host) or exposed as
individual properties (e.g. IfModifiedSince) of the HttpWebRequest class.
Thus, you'll have to use the lower level classes HttpWebRequest and
HttpWebResponse to make use of these HTTP features.

Cheers,

--
Joerg Jooss
jo*********@gmx.net

Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: A.M-SG | last post by:
Hi, I have an aspx page at the web server that provides PDF documents for smart client applications. Here is the code in aspx page that defines content type: Response.ContentType =...
1
by: Cheri Elkin | last post by:
I recieve the following error when attempting to download a file from our web server to be placed on our hard drive. Any clues as to why I would get this error? By the way, the directory already...
8
by: DEWright_CA | last post by:
Why does WebClient.DownloadFile loose my completed path? Ok, I have a function in my app then when my button is clicked it checks to see if the files come from a local drive or a http address....
1
by: peter.rietmann | last post by:
I have been suddenly having a performance problem downloading images from one server (productive) to another (productive) using the following code .. WebClient webClient = new WebClient(); try...
2
by: Lila Godel | last post by:
I am having a problem with the download of web pages via the WebClient.DownloadFile function in the specialized VB.Net 2003 I.E. plug-in I am designing to speed up the work on my latest project. ...
1
by: James Write | last post by:
Hi, I am using the webclient.downloadfile() method to download a file from a remote web server to the local harddrive. public CopyFile(string sSrcPath, string sDestPath) { WebClient oClient...
1
by: vin.dor | last post by:
Dear All, I am using WebClient in my Visual Studio .Net 2003 project to download an image from the Internet. The following is my function: C# Code: public static bool downloadFile(string...
4
by: Harvey Triana | last post by:
Hi- I am using... WebClient Client = new WebClient (); Client.DownloadFile(url, filename); Or Stream strm = Client.OpenRead (url);
8
by: =?Utf-8?B?UnVpIE9saXZlaXJh?= | last post by:
WebClient.DownloadFile I am using the WebClient.DownloadFile function to download a file from server to a local client. When I execute the below code, file is created in server and not in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.