|
i have a text file in the web server.
It can be downloaded by a URL "http://servername/file.txt"
I want to be able to get the modify date out from the web server so as to compare it with the text file downloaded on the user desktop. If the file on the user desktop is older, I would like to overwrite the old one on the desktop by downloading the file from the web server.
How can I do that?
Thanks
|
|
|
This is not a complete answer, but to get you started, on the server, in your ASP/VBScript, you can use the filesystem object to retrieve the modified date of the text file. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/FSOoriFileSystemObject.asp?frame=true
Default script security won't allow you to work with the client's local filesystem, but if you have a controlled user base that will allow your script to run, then you can do what you want. This security is of course a good thing -- you don't want any web page being able to modify or even read your local files. The exception to this is the browser cache and cookie files.
|
|
|
|
|
Is there any way to get out a last modified date from a URL?
<Added>
I want to do it in vb only
<Added>
Please provide sample codes to explain how to do it.
|
|
|
The HTTP HEADER "Last-Modified" may be exactly what you are looking for. I'm not sure how reliable it is, but I just checked it for a remote HTML and JPG file, and it was correctly returned by my Apache server for both files.
Here is a web page with a cool utility to let you view HTTP Headers for a URL. http://www.rexswain.com/httpview.html
Input the URL to your file, and see if it isn't what you want.
Here is sample code using ASP/VBScript to perform this task. It relies on the Microsoft XML Core Services component, so you'll need to have that installed on the client for this to work! If you are mass-distributing this client app, this will probably not be a good solution! I believe the .NET library has built-in modules for doing this same kind of thing, but I can't even try to help you with .NET.
set xmlhttp=Server.CreateObject("Msxml2.ServerXMLHTTP")
xmlhttp.open "GET","http://www.mydomain.com/myfolder/myfile.txt"
xmlhttp.send()
xmlresult=xmlhttp.responseText
modified_date = xmlhttp.getResponseHeader("Last-Modified")
response.Write(modified_date)
|
|
I'm not a VB programmer, but I think all you have to do to modify the above for VB is remove the "Server." from the first line. I tested the above code with both HTML and image files, so I assume it will work with other file types as well.
In case this helps, here is an ASP/VBScript example for how to get the last modified date of a local file. Again, to turn this into VB, I think all you have to do is remove the "Server." from the first line.
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set file = fso.GetFile(Server.MapPath("/index.html") & "/forum/some_file.txt")
Response.Write(file.DateLastModified)
|
|
|
|
|
|
|
snowei1, don't forget to follow up here in the forum with your solution. Without feedback, future forum readers are left wondering if the "expert" answer was accurate.
Thanks for using codetoad.com forums! :)
|
|
|
|
|
Never mind I use Inet control and get the date and then trim it to what I want and give it to variable date
<Added>
Ok,now to make it more clear. I use Inet control to get the header of last-modified date. Then I trim of the weekday and the GMT which is suppose to be found when I get the last-modified date in the server.
After that I format it to a date like dd-mm-yyyy hh:nn:ss.
There the date is found.
Thanks to everyone who helped.
|
|
|
|
|
|
|
// |