vb.net FileDateTime function in C#?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ron

    vb.net FileDateTime function in C#?

    Yes, I am trying to use the FileDateTime function from
    vb.net in C#. I am just starting out in C#. Here is how
    I use FileDateTime in vb.net:

    Dim NewDate As DateTime
    NewDate = FileDateTime("C :\SomeDir\TestF ile.txt")

    In C# I got this far:

    DateTime NewDate;
    NewDate = FileDateTime("C :\SomeDir\TestF ile.txt");

    FileDateTime returns the creation Date-Time of a file in
    vb.net. How can I implement this functionality in C#? Is
    there a using library I need to add? If there is no
    FileDateTime equivalent in C#, may I ask what code to use
    to retrieve File CreateDate-Time information?

    Thanks,
    Ron

  • MuZZy

    #2
    Re: vb.net FileDateTime function in C#?

    Ron wrote:[color=blue]
    > Yes, I am trying to use the FileDateTime function from
    > vb.net in C#. I am just starting out in C#. Here is how
    > I use FileDateTime in vb.net:
    >
    > Dim NewDate As DateTime
    > NewDate = FileDateTime("C :\SomeDir\TestF ile.txt")
    >
    > In C# I got this far:
    >
    > DateTime NewDate;
    > NewDate = FileDateTime("C :\SomeDir\TestF ile.txt");
    >
    > FileDateTime returns the creation Date-Time of a file in
    > vb.net. How can I implement this functionality in C#? Is
    > there a using library I need to add? If there is no
    > FileDateTime equivalent in C#, may I ask what code to use
    > to retrieve File CreateDate-Time information?
    >
    > Thanks,
    > Ron
    >[/color]


    Hi Ron,

    There is a class FileInfo in C#, which gives you the file info :)

    ------------------------------------------------------------------------
    using Sustem.IO;// You need to add this library

    FileInfo fi = new FileInfo("filen ame.ext");
    DateTime ct = fi.CreationTime ;
    ------------------------------------------------------------------------

    For additional members/functions of FileInfo class you can lookup on
    msdn, for example here:



    Hope it helps,
    Andrey aka MuZZy




    Comment

    • Ron

      #3
      Re: vb.net FileDateTime function in C#?

      Thanks. Yes, this is very helpful. I also found this:

      NewDate = File.GetCreatio nTime("C:\\some dir\\Test.txt") ;
      NewDate = File.GetLastWri teTime("C:\\som edir\\Test.txt" );

      Is there any significant difference between File and
      FileInfo?

      Thanks for your help.
      [color=blue]
      >-----Original Message-----
      >Ron wrote:[color=green]
      >> Yes, I am trying to use the FileDateTime function from
      >> vb.net in C#. I am just starting out in C#. Here is[/color][/color]
      how[color=blue][color=green]
      >> I use FileDateTime in vb.net:
      >>
      >> Dim NewDate As DateTime
      >> NewDate = FileDateTime("C :\SomeDir\TestF ile.txt")
      >>
      >> In C# I got this far:
      >>
      >> DateTime NewDate;
      >> NewDate = FileDateTime("C :\SomeDir\TestF ile.txt");
      >>
      >> FileDateTime returns the creation Date-Time of a file[/color][/color]
      in[color=blue][color=green]
      >> vb.net. How can I implement this functionality in C#?[/color][/color]
      Is[color=blue][color=green]
      >> there a using library I need to add? If there is no
      >> FileDateTime equivalent in C#, may I ask what code to[/color][/color]
      use[color=blue][color=green]
      >> to retrieve File CreateDate-Time information?
      >>
      >> Thanks,
      >> Ron
      >>[/color]
      >
      >
      >Hi Ron,
      >
      >There is a class FileInfo in C#, which gives you the file[/color]
      info :)[color=blue]
      >
      >----------------------------------------------------------[/color]
      --------------[color=blue]
      >using Sustem.IO;// You need to add this library
      >
      >FileInfo fi = new FileInfo("filen ame.ext");
      >DateTime ct = fi.CreationTime ;
      >----------------------------------------------------------[/color]
      --------------[color=blue]
      >
      >For additional members/functions of FileInfo class you[/color]
      can lookup on[color=blue]
      >msdn, for example here:
      >http://msdn.microsoft.com/library/default.asp?[/color]
      url=/library/en-
      us/cpref/html/frlrfSystemIOFi leInfoClassTopi c.asp[color=blue]
      >
      >
      >Hope it helps,
      >Andrey aka MuZZy
      >
      >
      >
      >
      >.
      >[/color]

      Comment

      • MuZZy

        #4
        Re: vb.net FileDateTime function in C#?

        Ron wrote:[color=blue]
        > Thanks. Yes, this is very helpful. I also found this:
        >
        > NewDate = File.GetCreatio nTime("C:\\some dir\\Test.txt") ;
        > NewDate = File.GetLastWri teTime("C:\\som edir\\Test.txt" );
        >
        > Is there any significant difference between File and
        > FileInfo?
        >[/color]

        Quote from MSDN Help:

        The static methods of the File class perform security checks on all
        methods. If you are going to reuse an object several times, consider
        using the corresponding instance method of FileInfo instead, because the
        security check will not always be necessary.
        [/END OF QUOTE]

        I guess that's about the only difference, at least among the obvious ones.


        Andrey


        [color=blue]
        > Thanks for your help.
        >
        >[color=green]
        >>-----Original Message-----
        >>Ron wrote:
        >>[color=darkred]
        >>>Yes, I am trying to use the FileDateTime function from
        >>>vb.net in C#. I am just starting out in C#. Here is[/color][/color]
        >
        > how
        >[color=green][color=darkred]
        >>>I use FileDateTime in vb.net:
        >>>
        >>>Dim NewDate As DateTime
        >>>NewDate = FileDateTime("C :\SomeDir\TestF ile.txt")
        >>>
        >>>In C# I got this far:
        >>>
        >>>DateTime NewDate;
        >>>NewDate = FileDateTime("C :\SomeDir\TestF ile.txt");
        >>>
        >>>FileDateTi me returns the creation Date-Time of a file[/color][/color]
        >
        > in
        >[color=green][color=darkred]
        >>>vb.net. How can I implement this functionality in C#?[/color][/color]
        >
        > Is
        >[color=green][color=darkred]
        >>>there a using library I need to add? If there is no
        >>>FileDateTi me equivalent in C#, may I ask what code to[/color][/color]
        >
        > use
        >[color=green][color=darkred]
        >>>to retrieve File CreateDate-Time information?
        >>>
        >>>Thanks,
        >>>Ron
        >>>[/color]
        >>
        >>
        >>Hi Ron,
        >>
        >>There is a class FileInfo in C#, which gives you the file[/color]
        >
        > info :)
        >[color=green]
        >>----------------------------------------------------------[/color]
        >
        > --------------
        >[color=green]
        >>using Sustem.IO;// You need to add this library
        >>
        >>FileInfo fi = new FileInfo("filen ame.ext");
        >>DateTime ct = fi.CreationTime ;
        >>----------------------------------------------------------[/color]
        >
        > --------------
        >[color=green]
        >>For additional members/functions of FileInfo class you[/color]
        >
        > can lookup on
        >[color=green]
        >>msdn, for example here:
        >>http://msdn.microsoft.com/library/default.asp?[/color]
        >
        > url=/library/en-
        > us/cpref/html/frlrfSystemIOFi leInfoClassTopi c.asp
        >[color=green]
        >>
        >>Hope it helps,
        >>Andrey aka MuZZy
        >>
        >>[/color][/color]

        Comment

        Working...