How to get file properties?

I need an application that displays some properties of a media file, if available, for example (I don’t know which English words are used in Windows) FileName, Length / Duration, FileType (.avi.mp3, etc.). I tried taglib and windowsapishell, but I don't get a working result (links are good)

ShellFile so = ShellFile.FromFilePath(file);
so.Properties.System.(everythingIwant)

shows me a lot of file properties that I want to display, but I cannot get it to work. Example error:

'WindowsFormsApplication2.vshost.exe' (Managed (v4.0.30319)): Loaded 'C: \ Windows \ Microsoft.Net \ assembly \ GAC_MSIL \ WindowsBase \ v4.0_4.0.0.0__31bf3856ad364e35 \ WindowsBase.dll', skipped character loading. The module is optimized and the debugger option "Only my code" is enabled. The program "[6300] WindowsFormsApplication2.vshost.exe: Program Trace" exited with code 0 (0x0). The program "[6300] WindowsFormsApplication2.vshost.exe: Managed (v4.0.30319)" exited with code 0 (0x0).

something simple like

var thing = so.Properties.System.FileName.Description;
Console.WriteLine(thing);

does not work

I know some Java and PHP programming, but I'm completely new to C #


Special thanks to @ marr75 and @errorstacks!

one next question: I did it and it works

class Program
{
    static void Main(string[] args)
    {   
        string file = "E:/Dump/Shutter Island.avi";

        FileInfo oFileInfo = new FileInfo(file);
        Console.WriteLine("My File Name: \"" + oFileInfo.Name + "\"");
        DateTime dtCreationTime = oFileInfo.CreationTime;
        Console.WriteLine("Date and Time File Created: " + dtCreationTime.ToString());
        Console.WriteLine("myFile Extension: " + oFileInfo.Extension);
        Console.WriteLine("myFile total Size: " + oFileInfo.Length.ToString());
        Console.WriteLine("myFile filepath: " + oFileInfo.DirectoryName);
        Console.WriteLine("My File Full Name: \"" + oFileInfo.FullName + "\"");

    }               
}

but I want him to provide me only information if information exists. I have seen

   **Exists**   Gets a value indicating whether a file exists. (Overrides FileSystemInfo.Exists.)

, , , (io.ofileinfo.FullName.exist) {Console.Write(io.ofileinfo.fullname);}?

+5
2

, .... #

, , FileInfo Name. :

FileInfo oFileInfo = new FileInfo(strFilename);

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

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

, , " ", .

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

, FileSystemInfo.Extension.

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

.

, FileInfo class - , , , .

?

+3

All Articles