FileVersionInfo Class
Provides version information for a physical file on disk.
For a list of all members of this type, see FileVersionInfo Members.
System.Object
System.Diagnostics.FileVersionInfo
[Visual Basic] NotInheritable Public Class FileVersionInfo [C#] public sealed class FileVersionInfo [C++] public __gc __sealed class FileVersionInfo [JScript] public class FileVersionInfo
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Remarks
Typically, a version number is displayed as "major number.minor number.build number.private part number". A file version number is a 64-bit number that holds the version number for a file as follows:
- The first 16 bits are the FileMajorPart number.
- The next 16 bits are the FileMinorPart number.
- The third set of 16 bits are the FileBuildPart number.
- The last 16 bits are the FilePrivatePart number.
Use the GetVersionInfo method of this class to get a FileVersionInfo containing information about a file, then look at the properties for information about the file. The FileVersion property provides version information about the file. The ProductMajorPart, ProductMinorPart, ProductBuildPart, ProductPrivatePart, and ProductVersion properties provide version information for the product that the specified file is a part of. Call ToString to get a partial list of properties and their values for this file.
Example
The following example calls GetVersionInfo to get the FileVersionInfo for the Notepad. Then it prints the file description and version number in a text box. This code assumes textBox1 has been instantiated.
[Visual Basic] Public Sub GetFileVersion() ' Get the file version for the notepad. Dim myFileVersionInfo As FileVersionInfo = FileVersionInfo.GetVersionInfo("%systemroot%\Notepad.exe") ' Print the file name and version number. textBox1.Text = "File: " & myFileVersionInfo.FileDescription & ControlChars.Cr & _ "Version number: " & myFileVersionInfo.FileVersion End Sub 'GetFileVersion [C#] public void GetFileVersion() { // Get the file version for the notepad. FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo("%systemroot%\\Notepad.exe"); // Print the file name and version number. textBox1.Text = "File: " + myFileVersionInfo.FileDescription + '\n' + "Version number: " + myFileVersionInfo.FileVersion; } [C++] public: void GetFileVersion() { // Get the file version for the notepad. FileVersionInfo* myFileVersionInfo = FileVersionInfo::GetVersionInfo(S"%systemroot%\\Notepad.exe"); // Print the file name and version number. textBox1->Text = String::Format( S"File: {0}\nVersion number: {1}", myFileVersionInfo->FileDescription, myFileVersionInfo->FileVersion ); } [JScript] public function GetFileVersion() { //Get the file version for the notepad. var myFileVersionInfo : FileVersionInfo = FileVersionInfo.GetVersionInfo("%systemroot%\\Notepad.exe"); //Print the file name and version number. textBox1.Text = "File: " + myFileVersionInfo.FileDescription + '\n' + "Version number: " + myFileVersionInfo.FileVersion; }
Requirements
Namespace: System.Diagnostics
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
Assembly: System (in System.dll)
See Also
FileVersionInfo Members | System.Diagnostics Namespace | FileVersion | Version