Wednesday, October 25, 2006

File Properties using C#

File Name of your file:

When reviewing or opening a file, to get its name, the FileInfo class is equipped with the Name property. Here is an sample code:


FileInfo oFileInfo = new FileInfo(strFilename);
MessageBox.Show("My File's Name: \"" + oFileInfo.Name + "\"");


Date and Time a File Created

The Operating System takes care to keep track of the date and time of a file was created. To find out what those date and time values are, you can access the File System Information property using.

DateTime dtCreationTime = oFileInfo.CreationTime;
MessageBox.Show("Date and Time File Created: " + dtCreationTime.ToString());

Find your file extension:

When you access a file or when the user opens one, to know the extension of the file, you can access the value of the FileSystemInfo.Extension property.

MessageBox.Show("myFile Extension: " + oFileInfo.Extension);

Find file size using C#:

One of the routine operations the operating system performs consistly for all the file is calculating the size of files it holds.

MessageBox.Show("myFile total Size: " + oFileInfo.Length.ToString());

a

2 comments:

Unknown said...

Hi,

Is there any way to determine the file size before content upload?

Or is it possible to extract meta data alone before upload.

Dj said...

use FileInfo.Length for size

ASP.NET MVC - Sport Facility Booking system

  The project relies on some external service providers. Thus accessing them via their API requires authentication. An API Key need to be su...