FileVersionInfo.GetVersionInfo(String) 方法

定义

返回表示与指定文件关联的版本信息的 FileVersionInfo

public:
 static System::Diagnostics::FileVersionInfo ^ GetVersionInfo(System::String ^ fileName);
public static System.Diagnostics.FileVersionInfo GetVersionInfo (string fileName);
static member GetVersionInfo : string -> System.Diagnostics.FileVersionInfo
Public Shared Function GetVersionInfo (fileName As String) As FileVersionInfo

参数

fileName
String

要检索其版本信息的文件的完全限定路径和名称。

返回

包含文件信息的 FileVersionInfo。 如果文件不包含版本信息,则 FileVersionInfo 仅包含所请求文件的名称。

例外

找不到指定的文件。

示例

以下示例调用 GetVersionInfo 以获取 FileVersionInfo 记事本的 ,并在控制台窗口中显示文件说明和版本号。

#using <System.dll>

using namespace System;
using namespace System::IO;
using namespace System::Diagnostics;


public ref class Class1
{
    
public:
    static void Main()
    {
        // Get the file version for the notepad.
        // Use either of the two following methods.
        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);
    }
};

int main()
{
    Class1::Main();
}

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);
    }
}
Imports System.IO
Imports System.Diagnostics



Class Class1

    Public Shared Sub Main(ByVal args() As String)
        ' Get the file version for the notepad.
        ' Use either of the following two commands.
        FileVersionInfo.GetVersionInfo(Path.Combine(Environment.SystemDirectory, "Notepad.exe"))
        Dim myFileVersionInfo As FileVersionInfo = FileVersionInfo.GetVersionInfo(Environment.SystemDirectory + "\Notepad.exe")


        ' Print the file name and version number.
        Console.WriteLine("File: " + myFileVersionInfo.FileDescription + vbLf + "Version number: " + myFileVersionInfo.FileVersion)

    End Sub
End Class

适用于

另请参阅