FileVersionInfo.GetVersionInfo(String) Method

Definition

Returns a FileVersionInfo representing the version information associated with the specified file.

C#
public static System.Diagnostics.FileVersionInfo GetVersionInfo(string fileName);

Parameters

fileName
String

The fully qualified path and name of the file to retrieve the version information for.

Returns

A FileVersionInfo containing information about the file. If the file did not contain version information, the FileVersionInfo contains only the name of the file requested.

Exceptions

The file specified cannot be found.

Examples

The following example calls GetVersionInfo to get the FileVersionInfo for Notepad and displays the file description and version number in the console window.

C#

using System;
using System.IO;
using System.Diagnostics;

class Class1
{
    public static void Main(string[] args)
    {
        // Get the file version for the notepad.
        // Use either of the two following commands.
        FileVersionInfo.GetVersionInfo(Path.Combine(Environment.SystemDirectory, "Notepad.exe"));
        FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(Environment.SystemDirectory + "\\Notepad.exe");

        // Print the file name and version number.
        Console.WriteLine("File: " + myFileVersionInfo.FileDescription + '\n' +
           "Version number: " + myFileVersionInfo.FileVersion);
    }
}

Applies to

Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

See also