How to find version of file programatically in .Net 2005?

Hi,

I wanted to know how I can find the version of a file programatically using C# .Net2005.

I am using FileInfo[ ] info = Directory.GetFiles() to get all the files in the directory.But I am not able to get the version attribute of the file.

Any help is highly appreciated

Regards,

~nhd



Answer this question

How to find version of file programatically in .Net 2005?

  • roy-roy

    Thanks, chris! It's simple enough and works fine.

  • Romantic_touch

    Yes, not all files have versions.

    But I want to find versions for files with .dll,.exe

    can i get the versions programatically


  • Alessandro Camargo

    Hi nhd,

    Then try the unsafe code in the article. (example 3). It gets the product version of the file.



  • PsychUK

    Thanks a lot Chris..

    It is working fine

    ~nhd


  • gteddy

    No, you don't need unsafe code in extracting version information of executable files. There is a class called FileVersionInfo in System.Diagnostics namespace, and it's accessible to your program.

    Here's an example:



    FileVersionInfo notepadInfo =
    FileVersionInfo.GetVersionInfo("%systemroot%\\notepad.exe");



    From the call above, the notepadInfo object will be filled with version information of notepad.exe.



    Debug.WriteLine("File Description : " + notepadInfo.FileDescription);
    Debug.WriteLine("File Version : " + notepadInfo.FileVersion);



    Regards,

    -chris



  • ijrr

    Hi nhd,

    I'm afraid that not all files have the version attribute, for example the basic 'txt' file. However, you can get a lot of information from the FileInfo class.



  • How to find version of file programatically in .Net 2005?