Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

FREE 12 month online training for ASP.NET & MS Expression Studio and a Free copy of MS Expression Web with Windows Server Purchase
How to get file creation date and other useful information using VB.NET in .NET 2.0

Author: Aadil

In this article I’ll show you how to get the information relating the creation date time of files in a folder and other related information.

You can get various details about the files present on the file system by using the new capabilities added in the FileInfo class. First of all the Arrtibutes property of this class is there so you can use that to find the various attributes of the specific file. There is a property named CreateTime that represents the creation time of the file. This is a readable and writable property and it is a DateTime object. So you can get as well set the Creation time for a file using this property.

 

You can encrypt a file using the built in capabilities of the windows file systems, like the NTFS file system using the Encrypt method and there is a method Decrypt that can be use to reverse the same process. Similarly you can get the file’s last access time and the last write time using these two properties LastAccessTime and LastWriteTime, respectively.

 

The MoveTo() method takes a single argument and simulates a move operation and moves the file to the new destination path supplied in the argument. The file will be disappeared from the source path.

 

Similarly you can use the AppendText method to get an object of StreamWriter that is set to do appending on the file. It means you can just use this operation and use the StreamWriter to appends any data to the file. A sample function using this object is as follows.

 

Sub FileInfoTest()

Dim objFileInfo As New FileInfo("D:\64.jpg")

'To get the creation, lastaccess, lastwrite time of this file

Dim dtCreationDate As DateTime = objFileInfo.CreationTime

Dim dtLastAccessTime As DateTime = objFileInfo.LastAccessTime

Dim dtLastWriteTime As DateTime = objFileInfo.LastWriteTime

'To encrypt and decrypt the file

objFileInfo.Encrypt()

objFileInfo.Decrypt()

'Now to move the file from one place to another

objFileInfo.MoveTo("C:\64.jpg")

End Sub

Article Comments
Anyone know how to get the creator of the file, is this one of the file attributes you would have to be into an array and parse out?

Posted on 4/14/2010 10:24:55 AM by Marty Barnett

i am developing software in vb6
Any Help?

Posted on 4/17/2010 4:30:03 AM by kamlesh mehta

can anyone tell the code for creating a directory with current date in vb.net

Posted on 6/4/2010 11:14:34 AM by deepu

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Creating and Using User Controls in ASP.Net

Disclaimer - Privacy
© 2002-2012 DevASP.net