How to get the LastWriteTime of a remote file (IIS) ?

  • Thread starter Thread starter patrick.roy
  • Start date Start date
P

patrick.roy

Hi,

I would like to "GetLastWriteTime" of a file that is located on my IIS
server without having to download it.

My goal is to download the file ONLY if the file is more recent on
IIS.

He're my code :

localFileName = string.Format(@"{0}{1}\{2}", localSyncPath,
ApplicationFolder.Help, line);
url = string.Format("http://{0}/ATMP/{1}/{2}", serverIPAddress,
IISHelpPath, line);

if (File.GetLastWriteTime(localFileName) < File.GetLastWriteTime(url))
{
NetworkUtil.DownloadFile(url, localFileName);
}

When I run that code, I got an error because the function
File.GetLastWriteTime(url) does'nt seems to accept url file like
"http://10.121.128.16/ATMP/Help/1Options.htm".
The exact error is (in french) : "La valeur n'est pas comprise dans la
plage attendue."
Translated in english, it should sounds like "Value is not included in
planned range"... Sorry for my bad translation :-)

Also, the Stacktrace start by : at
System.IO.Path.GetFullPathInternal() at
System.IO.File.GetLastWriteTime() at ...

Thank you.
 
You certainly won't be able to use File-based calls to determine the date
time of 'some resource' on a Web server. It's not a file, as far as
anything on the Windows CE device knows. It's not even a 'what' that the
File class understands. It's just a URL not a reference to a file in a
real, local filesystem.

There may be some method that you could use to query the Web server for the
date of that item. In particular, I'm thinking that creating an
HttpWebRequest instance and setting the IfModifiedSince property to the date
you care about and arranging the rest of the request to get the target item
might do what you need. You'd have to handle treating the response to your
request (it might contain a file or nothing, depending on the date), and
writing the file.

Paul T.
 
Dans : Paul G. Tobey [eMVP] disait :
There may be some method that you could use to query the Web server
for the date of that item. In particular, I'm thinking that creating
an HttpWebRequest instance and setting the IfModifiedSince property
to the date you care about and arranging the rest of the request to
get the target item might do what you need. You'd have to handle
treating the response to your request (it might contain a file or
nothing, depending on the date), and writing the file.

And don't forget that the date and time can be different on each side.
 
Back
Top