Wrox Programmer Forums
|
BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9
This is the forum to discuss the Wrox book Professional ASP.NET 2.0 Special Edition by Bill Evjen, Scott Hanselman, Devin Rader, Farhan Muhammad, Srinivasa Sivakumar; ISBN: 9780470041789
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 17th, 2007, 02:51 PM
Friend of Wrox
 
Join Date: Oct 2005
Posts: 124
Thanks: 0
Thanked 1 Time in 1 Post
Default Syntax for DateTime FileDate

I am coding a VB ASP.NET file to get the LastWriteTime for a http file.

DateTime FileDate;
        FileDate = System.IO.File.GetLastWriteTime(Server.MapPath("ht tp://sca3a56/iTemplates/PR/PhoneReport_lev1.asp"));
        DateLabel1.Text = FileDate.ToString(": MM/dd/yyyy");

The first error msg I got was: 'DateTime' is a type and cannot be used as an expression. In fact, I was modifying a C# code.

How do I code DateTime FileDate in VB?

TIA,
Jeffrey
__________________
C. Jeffrey Wang
 
Old July 17th, 2007, 04:46 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Did you change anything at all?? This looks like straight C# to me as you haven't even removed the ;

Try this (untested):

Dim FileDate As DateTime
FileDate = System.IO.File.GetLastWriteTime(Server.MapPath("ht tp://sca3a56/iTemplates/PR/PhoneReport_lev1.asp"))
DateLabel1.Text = FileDate.ToString(": MM/dd/yyyy")

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old July 17th, 2007, 04:52 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

BTW: Server.MapPath only works with local paths, not with internet addresses. So you can use something like "/Images/Whatever.gif" but not http addresses.

Same goes for the methods in the IO.File class.

Cheers,

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old July 17th, 2007, 09:26 PM
Friend of Wrox
 
Join Date: Oct 2005
Posts: 124
Thanks: 0
Thanked 1 Time in 1 Post
Default

Thanks.

Yes, I have written the same VB code and got the error msg that
the http file can not be found. Then for a href http file
how do I code the file.GetLastWriteTime()?

TIA,
Jeffrey
 
Old July 18th, 2007, 01:52 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You may want to look at the WebRequest and WebResponse classes: http://msdn2.microsoft.com/en-us/library/system.net.httpwebresponse.lastmodified(VS.71).asp x

However, this doesn't really return the file's date on disk. If you really need that, you could create a web service that returns the date and time for a specific file on the local machine using code similar to what you posted earlier. Then your ASP.NET site could connect to this web service.

Cheers,

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old July 18th, 2007, 03:43 PM
Friend of Wrox
 
Join Date: Oct 2005
Posts: 124
Thanks: 0
Thanked 1 Time in 1 Post
Default

Just tried the inline VB code:

Protected Sub DateLabel4_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim FileDate As DateTime
        FileDate = System.IO.File.GetLastWriteTime("\\sca4001\DARS DDS\Home.aspx")
        DateLabel4.Text = FileDate.ToString(": MM/dd/yyyy")
    End Sub

sca4001 is my other server. Many times, including the local server,
the FileDate seemed to be working, but the label date was 12/31/1600.
What does 12/31/1600 mean? The coding was correct, but the ToString was wrong? Or the FileDate is still wrong, so the filedate is empty?

TIA,
Jeffrey
 
Old July 19th, 2007, 04:33 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Take a look at the docs here: http://msdn2.microsoft.com/en-us/lib...writetime.aspx

31-12 1600 is returned when the file could not be found. It may also be a permission issue....

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Syntax error converting datetime from character st vinod_yadav1919 SQL Server 2000 2 September 10th, 2010 10:11 AM
datetime MathLearner Beginning VB 6 0 November 15th, 2007 07:12 AM
Syntax error converting datetime from character st kkrish SQL Server 2000 11 September 6th, 2006 06:46 AM
UTC DateTime to Local DateTime r_ganesh76 SQL Server 2000 1 April 4th, 2005 08:21 AM
Syntax error converting datetime from character st Uppa SQL Server 2000 2 February 8th, 2005 08:01 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.