Results 1 to 4 of 4

Thread: [Resolved] System.IO.FileInfo - Date Modified

  1. #1

    Thread Starter
    Addicted Member jordan23's Avatar
    Join Date
    Dec 2002
    Posts
    166

    [Resolved] System.IO.FileInfo - Date Modified

    I am trying to get the same date/time as you see in windows explorer for a file and I am using the following code.

    Code:
                    FileInfo myInfo = new FileInfo(listBox1.Items[i].ToString()) ;
                    myInfo.Refresh();
                    string dateInfo = myInfo.LastWriteTime.Date.ToLongDateString() + " " + myInfo.LastWriteTime.Date.ToLongTimeString();
    The date is correct but the time is always 12:00. Any ideas? Thanks in advance.
    Last edited by jordan23; Aug 24th, 2007 at 06:18 AM. Reason: Resolved

  2. #2
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: System.IO.FileInfo - Date Modified

    It is due to the 'Date' when you are converting to a string. However, you don't need to concatenate like that. This should give you what you want.

    c# Code:
    1. myInfo.LastWriteTime.ToString("F")

    http://msdn2.microsoft.com/en-us/library/az4se3k1.aspx

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: System.IO.FileInfo - Date Modified

    nmadd is quite correct. The MSDN library has all the details of format strings for formatting dates, times and numbers.

    http://search.msdn.microsoft.com/sea...=00&lang=en-us
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Addicted Member jordan23's Avatar
    Join Date
    Dec 2002
    Posts
    166

    Re: System.IO.FileInfo - Date Modified

    Thanks nmadd. Works perfectly.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width