FileVersionInfo.GetVersionInfo(String) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
傳回 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
適用於
另請參閱
- 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