473,662 Members | 2,631 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

get file details for HTTP location

Hi, is there any way of getting details (such as last modified/created
date/time) of a file located on the web?

E.g I'd like to know when the file "http://www.myWebSite.c om/
update.txt" was last created/modified.

Cheers,

Tony.

Sep 18 '07 #1
8 6417
Hello, ba********@hotm ail.com!

With general HTTP access there is no way to get these values.
If that file will be located on FTP server then some of the mentioned
properties will be available.

If only HTTP access is available, you can add special page on the server
that will return update.txt upon request and specify necessary attributes in
the HTTP headers.

HTH
--
With best regards, Vadym Stetsiak.
Blog: http://vadmyst.blogspot.com

You wrote on Tue, 18 Sep 2007 10:49:47 -0000:

btHi, is there any way of getting details (such as last
btmodified/created date/time) of a file located on the web?

btE.g I'd like to know when the file "http://www.myWebSite.c om/
btupdate.txt" was last created/modified.

btCheers,

btTony.
Sep 18 '07 #2
Vadym Stetsiak wrote:
Hello, ba********@hotm ail.com!

With general HTTP access there is no way to get these values.
This is incorrect. Normal webservers will return an HTTP header
Last-Modified that contains this information.

To the OP: See "14.29 Last-Modified" in
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html for information
on what to expect in response.

Some webservers may not respond properly with Last-Modified, so it's
best to ensure your target uses proper headers before relying on it (and
even then, it's subject to change).

Chris.
Sep 18 '07 #3
On Sep 18, 10:48 pm, Chris Shepherd <c...@nospam.ch sh.cawrote:
Vadym Stetsiak wrote:
Hello, baker_t...@hotm ail.com!
With generalHTTPacce ss there is no way to get these values.

This is incorrect. Normal webservers will return anHTTPheader
Last-Modified that contains this information.

To the OP: See "14.29 Last-Modified" inhttp://www.w3.org/Protocols/rfc2616/rfc2616-sec14.htmlfor information
on what to expect in response.

Some webservers may not respond properly with Last-Modified, so it's
best to ensure your target uses proper headers before relying on it (and
even then, it's subject to change).

Chris.
Hi,

I am tryng to write a windows service that will retrieve csv files and
other files over HTTP. I only want to get those files that have been
updated recently. Considering the discussion above do you think this
is an unreliable way to go? Maybe I should try look at ftp?

I cant seem to get the last-modified property off the header... here
is some sample code I am testing:

Any help would be greatly appreciated... thanks!

*************** *************** *************** *************** *************** *************** *************** *************** *************** *************** *******

System.Net.WebR equest req = System.Net.Http WebRequest.Crea te("http://
uri/TestHTML.htm");
string last = req.Headers["If-Modified-Since"];
IEnumerator cacheEnum = req.Headers.Get Enumerator();
while (cacheEnum.Move Next())
{
string strKey = cacheEnum.Curre nt.ToString();
}

Sep 19 '07 #4
On Sep 19, 9:16 am, gwell <gavincolw...@g mail.comwrote:
I cant seem to get the last-modified property off the header... here
is some sample code I am testing:

Any help would be greatly appreciated... thanks!
*************** *************** *************** *************** *************** *************** *************** *************** *************** *************** *******
>
System.Net.WebR equest req = System.Net.Http WebRequest.Crea te("http://
uri/TestHTML.htm");
string last = req.Headers["If-Modified-Since"];
IEnumerator cacheEnum = req.Headers.Get Enumerator();
while (cacheEnum.Move Next())
{
string strKey = cacheEnum.Curre nt.ToString();

}
You need to *add* the If-Modified-Since header yourself. The idea is
that you tell the server when you last fetched the data, and it can
either give you back the data or tell you that it hasn't changed.

Jon

Sep 19 '07 #5
Hello, gwell!

Ftp can be a better option here.
Another way, if you have access to the remote HTTP server (where CSVs are
hosted) and that server has, say, ASP.NET. Then you can code ASP.NET
web page that will return requested file along with necessary headers.

--
With best regards, Vadym Stetsiak.
Blog: http://vadmyst.blogspot.com

You wrote on Wed, 19 Sep 2007 01:16:47 -0700:

gOn Sep 18, 10:48 pm, Chris Shepherd <c...@nospam.ch sh.cawrote:
>Vadym Stetsiak wrote:
>>Hello, baker_t...@hotm ail.com!
>>With generalHTTPacce ss there is no way to get these values.
>This is incorrect. Normal webservers will return anHTTPheader
Last-Modified that contains this information.
>To the OP: See "14.29 Last-Modified"
inhttp://www.w3.org/Protocols/rfc2616/rfc2616-sec14.htmlfor
information on what to expect in response.
>Some webservers may not respond properly with Last-Modified, so it's
best to ensure your target uses proper headers before relying on it
(and even then, it's subject to change).
>Chris.
gHi,

gI am tryng to write a windows service that will retrieve csv files
gand other files over HTTP. I only want to get those files that have
gbeen updated recently. Considering the discussion above do you think
gthis is an unreliable way to go? Maybe I should try look at ftp?

gI cant seem to get the last-modified property off the header... here
gis some sample code I am testing:

gAny help would be greatly appreciated... thanks!

g************** *************** *************** *************** ***********
g************** *************** *************** *************** ***********
g************** ***

gSystem.Net.Web Request req = System.Net.Http WebRequest.Crea te("http://
guri/TestHTML.htm");
gstring last = req.Headers["If-Modified-Since"];
gIEnumerator cacheEnum = req.Headers.Get Enumerator();
gwhile (cacheEnum.Move Next())
g{
g string strKey = cacheEnum.Curre nt.ToString();
g}

Sep 19 '07 #6
gwell wrote:
I am tryng to write a windows service that will retrieve csv files and
other files over HTTP. I only want to get those files that have been
updated recently. Considering the discussion above do you think this
is an unreliable way to go? Maybe I should try look at ftp?
Here's the thing. I think FTP could be a good way to go if you had to do
this in multiple locations, where reliability may be in question. The
problem is most hosts nowadays do properly return the Last-Modified
header -- at the very least, all installs of Apache and IIS CAN return
the Last-Modified header, and do by default.

The major con with using an FTP connection is that you're doing quite a
bit more work to do what you could do with a simple HTTP request. The
overhead might be minimal, but in code, tracking FTP sites, logins,
etc., that's going to be far and away more work than simply tracking the
URL and checking its Last-Modified header.

Now, given your goal here of grabbing remote files via a service, I
think you should definitely stick to HTTP until such time as it becomes
an issue for you. Last-Modified is part of the RFC, so RFC-friendly
webservers will understand what you're looking for (which, just with the
two mentioned above accounts for something like 96%+ of all webservers
in use publicly on the Internet), and it's fairly trivial to implement.
I cant seem to get the last-modified property off the header... here
is some sample code I am testing:

Any help would be greatly appreciated... thanks!
[...]

Jon's response already covered the code stuff.

Chris.
Sep 19 '07 #7
On Sep 19, 10:21 pm, Chris Shepherd <c...@nospam.ch sh.cawrote:
gwell wrote:
I am tryng to write a windows service that will retrieve csv files and
other files overHTTP. I only want to get those files that have been
updated recently. Considering the discussion above do you think this
is an unreliable way to go? Maybe I should try look at ftp?

Here's the thing. I think FTP could be a good way to go if you had to do
this in multiple locations, where reliability may be in question. The
problem is most hosts nowadays do properly return the Last-Modified
header -- at the very least, all installs of Apache and IIS CAN return
the Last-Modified header, and do by default.

The major con with using an FTP connection is that you're doing quite a
bit more work to do what you could do with a simpleHTTPreque st. The
overhead might be minimal, but in code, tracking FTP sites, logins,
etc., that's going to be far and away more work than simply tracking the
URL and checking its Last-Modified header.

Now, given your goal here of grabbing remote files via a service, I
think you should definitely stick toHTTPuntil such time as it becomes
an issue for you. Last-Modified is part of the RFC, so RFC-friendly
webservers will understand what you're looking for (which, just with the
two mentioned above accounts for something like 96%+ of all webservers
in use publicly on the Internet), and it's fairly trivial to implement.
I cant seem to get the last-modified property off the header... here
is some sample code I am testing:
Any help would be greatly appreciated... thanks!

[...]

Jon's response already covered the code stuff.

Chris.
Hi,

Thanks for all the feedback. I have just got a proof of concept
working using HTTP and I'm going to start building the windows
service. I found the following article useful:

http://www.clariusconsulting.net/blo.../30/29105.aspx

Here is my updated code that I will work with -

Thanks for all your comments... much appreciated!

*************** *************** *************** *************** *************** *************** *************** *************** *************** *************** ***

// Create a request for the URL.
HttpWebRequest request = (HttpWebRequest )WebRequest.Cre ate("http://uri/
TestHTML.htm");

// If required by the server, set the credentials.
request.Credent ials = CredentialCache .DefaultCredent ials;
request.IfModif iedSince = DateTime.Parse( "23-07-2007");

try
{
using (WebResponse response = request.GetResp onse())
{
// Do something if the resource has changed.
}
}
catch (WebException wex)
{
HttpWebResponse httpResponse = wex.Response as HttpWebResponse ;
if (httpResponse.S tatusCode == HttpStatusCode. NotModified)
{
// resource was not modified.
}
// Something else happened. Rethrow or log.
throw;
}

Sep 20 '07 #8
Fantastic stuff! I managed to construct the following code which gives
me the last modified date time:

HttpWebRequest request =
(HttpWebRequest )WebRequest.Cre ate("http://www.teslaeurope .com/
default.htm");

// If required by the server, set the credentials.
//request.Credent ials =
CredentialCache .DefaultCredent ials;
//request.IfModif iedSince = DateTime.Parse( "01-01-1990");

try
{
using (WebResponse response = request.GetResp onse())
{
string lastModified = response.Header s["Last-
Modified"].ToString();
}
}
catch (WebException wex)
{
....

Oct 11 '07 #9

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

Similar topics

13
2310
by: Joseph Oget | last post by:
If I use the code below in a VB.NET form, even if the file exists, and is then executed, the Else statement produces the "Sorry cannot find the File " error message. The MessageBox.Show( StrPathToScript ) never gets called! why? If File.Exists( StrPathToScript ) Then MessageBox.Show( StrPathToScript )
3
1463
by: wschaub | last post by:
We need to inject information (i.e. server details from where a signed file was downloaded) into a signed file, without breaking the signature or integrity of a signed file. Apparently there are areas and ways to inject custom information into signed files, however, we cannot find the "how to". It is needed to inject server source when customer downloads signed files from a site, allowing the downloaded file to query the information and...
3
5243
by: Jim | last post by:
Hi, I have an assembly and it's satellite in my GAC. I have referenced the DLLs in my project (from the same location where I added it to the GAC). CopyLocal is set false. When I run the project I get our old friend: Parser Error Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error
8
4820
by: Krishnan Margabandhu | last post by:
I'm writing a Pocket PC app that will run when a device is first powered on. I want this program to get some data from the user and invoke a CAB file to install a software on the device. How do I invoke a CAB file from the VB app? Thanks
1
1676
by: brian.newman | last post by:
I'm trying to link a gridview to another gridview in a Master-Details architecture. But the Details list isn't filtering like it is suppossed to. It will show all items on page load and it won't remove any items when an item in the Masters list is selected. It shouldn't show anything until an item in the Master's list is selected and then only show the details which are associated with the selected item in the Masters list. I'm new to...
4
5482
by: kev | last post by:
Hi folks, I have created a database to store information on equipments. During the first level of registration, there is a form that i need the user to fill up details on the equipment testing. i have done this one.Now what i need is to enable the users to upload files and save it into the corresponding table. Example: 3. A laser inventory form has been completed for each 3b or 4 laser and submitted to the Laser Safety Officer...
12
4709
by: glennanthonyb | last post by:
Hi The company I work for has finally woken up to data security on our field laptops. I'm writing something in C# that will allow remote deletion of sensitive data and I don't believe File.Delete() will be sufficient. Is there anything in .NET that removes any remanence of the file? If it isn't going to be easy, does anyone know of a component that I can hook into to do the dirty work, free of otherwise?
4
6229
by: David | last post by:
Hi I'm using this code to import data from an excel spreadsheet: DoCmd.TransferSpreadsheet , acSpreadsheetTypeExcel9, "tblStudents", _ "\\Egusersrv\Staff - Shared Work\PE Teach & Report\Imported Spreadsheets/ImportStudents.xls", True Which works fine if the spreadsheet is always in the pre-defined location. Ideally what I would prefer to do is have the user locate
3
1937
by: grant | last post by:
Good day, How do I open a text file from the applications install location? I am currently opening a text file using "StreamReader sr = new StreamReader("DB.txt");" and then reading from that file. Problem is if I create a shortcut on the users desktop it tries to read that file from the desktop when I need it to read from the actual location of the executable.
0
8435
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8345
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8857
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8768
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8547
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5655
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4348
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2763
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1999
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.