This documentation is archived and is not being maintained.

FileVersionInfo.GetVersionInfo Method

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

[Visual Basic]
Public Shared Function GetVersionInfo( _
   ByVal fileName As String _
) As FileVersionInfo
[C#]
public static FileVersionInfo GetVersionInfo(
 string fileName
);
[C++]
public: static FileVersionInfo* GetVersionInfo(
 String* fileName
);
[JScript]
public static function GetVersionInfo(
   fileName : String
) : FileVersionInfo;

Parameters

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

Return Value

A FileVersionInfo containing information about the file. If the file was not found, the FileVersionInfo contains only the name of the file requested.

Exceptions

Exception Type Condition
FileNotFoundException The file specified cannot be found.

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

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

.NET Framework Security: 

See Also

FileVersionInfo Class | FileVersionInfo Members | System.Diagnostics Namespace | SpecialBuild | ProductVersion | ProductPrivatePart | ProductName | ProductMinorPart | ProductMajorPart | ProductBuildPart | PrivateBuild | OriginalFilename | LegalTrademarks | LegalCopyright | IsSpecialBuild | IsPreRelease | IsPrivateBuild | IsPatched | IsDebug | InternalName | FileVersion | FilePrivatePart | FileName | FileMinorPart | FileMajorPart | FileDescription | FileBuildPart | CompanyName | Comments

Show: