ASP 101 - Active Server Pages 101 - Web05
The Place ASP Developers Go!

Windows Technology Windows Technology
15 Seconds
ASP 101
ASP Wire
VB Forums
VB Wire
internet.commerce internet.commerce
Partners & Affiliates
ASP 101 is an site
ASP 101 is an site
Internet News
Small Business
Personal Technology

Corporate Info
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash

 Top ASP 101 Stories Top ASP 101 Stories
Connections, Commands, And Procedures
What is ASP?
VBScript Classes: Part 1 of N

Authenticating Anonymous requests
Show All Tips >>
ASP 101 RSS Feed ASP 101 Updates

Quick Tips

Modifying File Timestamps

While everyone knows that you can manipulate text files and their contents via an ASP.NET Web page, did you know that you can actually modify a file's timestamps just as easily? Why would you want to do that? Read on to find out.

While it's not something that everyone will have a need for, in certain situations it can be quite helpful to be able to modify a file's creation or last modified timestamp. While I'm sure you can probably come up with other reasons, I use it mainly to keep track of which files are modified after I post them to a client's site. If I set the last modified time so that it's the same for all the files in a project, then it's an extremely simple matter to tell at a glance which files have been changed after the client calls you saying their site is broken and they "haven't changed anything". I'm always happy to fix the errors that have been introduced... this just instantly tells me where to look to find them.

The sample code below illustrates the basic process. Here I simply change one file's properties, but changing a large number of files is simply a matter of looping through the files you want to modify and changing them on each file.

    Dim myDateTime As Date = New Date(2000, 1, 1, 12, 34, 56)
    Dim myFileInfo As FileInfo

    ' Get a handle on the file we're manipulating
    myFileInfo = New FileInfo(Server.MapPath("test.htm"))

    ' Change timestamps to new values
    myFileInfo.CreationTime = myDateTime
    myFileInfo.LastWriteTime = myDateTime

That's all there is to it. ASP.NET makes changing the values just as easy as reading them. Just make sure you log in as a user that has the appropriate (NTFS) permissions needed to modify the files you're working with.

Previous      Show All Tips      Next

If you have a tip you would like to submit, please send it to:

Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback
The Network for Technology Professionals



Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers