vb.net FileDateTime function in C#?

  • Thread starter Thread starter Ron
  • Start date Start date
R

Ron

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\TestFile.txt")

In C# I got this far:

DateTime NewDate;
NewDate = FileDateTime("C:\SomeDir\TestFile.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
 
Ron said:
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\TestFile.txt")

In C# I got this far:

DateTime NewDate;
NewDate = FileDateTime("C:\SomeDir\TestFile.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


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("filename.ext");
DateTime ct = fi.CreationTime;
------------------------------------------------------------------------

For additional members/functions of FileInfo class you can lookup on
msdn, for example here:
http://msdn.microsoft.com/library/d...pref/html/frlrfSystemIOFileInfoClassTopic.asp


Hope it helps,
Andrey aka MuZZy
 
Thanks. Yes, this is very helpful. I also found this:

NewDate = File.GetCreationTime("C:\\somedir\\Test.txt");
NewDate = File.GetLastWriteTime("C:\\somedir\\Test.txt");

Is there any significant difference between File and
FileInfo?

Thanks for your help.
 
Ron said:
Thanks. Yes, this is very helpful. I also found this:

NewDate = File.GetCreationTime("C:\\somedir\\Test.txt");
NewDate = File.GetLastWriteTime("C:\\somedir\\Test.txt");

Is there any significant difference between File and
FileInfo?

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
 
Back
Top