how to get file properties?

大憨熊 提交于 2019-11-28 00:05:11
Enigma State

you can try like this ....using c#

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);

if (FileName != null || FileName.Length == 0)
{
   MessageBox.Show("My File's Name: \"" + oFileInfo.Name + "\"");
   // For calculating the size of files it holds.
   MessageBox.Show("myFile total Size: " + oFileInfo.Length.ToString());
}

you can check like this

if (!oFileInfo.Exists)
{
    throw new FileNotFoundException("The file was not found.", FileName);
}

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());

To know the extension of the file, you can access the value of the FileSystemInfo.Extension property.

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

Here's a link with information about looking at the attributes.

Besides that, the FileInfo class is what you're probably looking to use.

What other kinds of properties are you looking at?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!