C# - Downloading files - Only download file if local filestamp is older than on server
How is it possible to download files from a server, and have C# only download the file if the timestamp on the local file is older than the file timestamp o开发者_开发问答n the server? In this case the two files have the same name, extension, etc...
For example file in web server:
http://www.test.com/test.txt
File on local computer:
C:\test.txt
You can use the HTTP If-Modified-Since header field to download a file only when it's newer than a given timestamp:
- Determine the LastWriteTime the local file.
- Send the HttpWebRequest with the IfModifiedSince property set to the LastWriteTime.
- If the remote file has been modified since the header value, a 200 OK response is returned as usual. Otherwise, a 304 NotModified response is returned, indicating that the remote file has not been modified since the header value.
Note that a 304 NotModified response causes a WebException to be thrown. See: Using If-Modified-Since in HTTP Requests.
See this link: http://www.codeguru.com/csharp/.net/net_general/internet/print.php/c16073
Basically your looking for a "conditional get" The link above should get you started.
精彩评论