Environment.GetFolderPath 方法   
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取由指定枚举标识的系统特殊文件夹的路径。
重载
| GetFolderPath(Environment+SpecialFolder) | 获取指定系统特殊文件夹的路径。 | 
| GetFolderPath(Environment+SpecialFolder, Environment+SpecialFolderOption) | 使用用于访问特殊文件夹的指定选项获取指定系统特殊文件夹的路径。 | 
GetFolderPath(Environment+SpecialFolder)
- Source:
- Environment.cs
- Source:
- Environment.cs
- Source:
- Environment.cs
获取指定系统特殊文件夹的路径。
public:
 static System::String ^ GetFolderPath(Environment::SpecialFolder folder);public static string GetFolderPath (Environment.SpecialFolder folder);static member GetFolderPath : Environment.SpecialFolder -> stringPublic Shared Function GetFolderPath (folder As Environment.SpecialFolder) As String参数
- folder
- Environment.SpecialFolder
标识系统特殊文件夹的枚举值之一。
返回
指定系统特殊文件夹的路径(如果计算机上存在该文件夹);否则为空字符串(“)。
如果操作系统未创建该文件夹、删除现有文件夹或文件夹是虚拟目录(如“我的计算机”),则文件夹将不存在于物理路径。
例外
              folder 不是 Environment.SpecialFolder的成员。
当前平台不受支持。
示例
以下示例演示如何使用 GetFolderPath 方法返回和显示与 folder 参数关联的路径。
// Sample for the Environment::GetFolderPath method
using namespace System;
int main()
{
   Console::WriteLine();
   Console::WriteLine( "GetFolderPath: {0}", Environment::GetFolderPath( Environment::SpecialFolder::System ) );
}
/*
This example produces the following results:
GetFolderPath: C:\WINNT\System32
*/
// Sample for the Environment.GetFolderPath method
using System;
class Sample
{
    public static void Main()
    {
    Console.WriteLine();
    Console.WriteLine("GetFolderPath: {0}",
                 Environment.GetFolderPath(Environment.SpecialFolder.System));
    }
}
/*
This example produces the following results:
GetFolderPath: C:\WINNT\System32
*/
// Sample for the Environment.GetFolderPath method
open System
printfn $"\nGetFolderPath: {Environment.GetFolderPath Environment.SpecialFolder.System}"
            
// This example produces the following results:
//     GetFolderPath: C:\WINNT\System32
' Sample for the Environment.GetFolderPath method
Class Sample
   Public Shared Sub Main()
      Console.WriteLine()
      Console.WriteLine("GetFolderPath: {0}", Environment.GetFolderPath(Environment.SpecialFolder.System))
   End Sub
End Class
'
'This example produces the following results:
'
'GetFolderPath: C:\WINNT\System32
'
注解
此方法检索系统特殊文件夹的路径,例如 Program Files、Programs、System 或 Startup,可用于访问通用信息。 在安装 Windows 版本时,系统默认或由用户显式设置特殊文件夹。
              folder 参数指定要检索的特殊文件夹,并且必须是 Environment.SpecialFolder 枚举中的值之一;任何其他值都引发异常。
有关特殊文件夹的详细信息,请参阅 常量特殊项 ID 列表(CSIDL)。
另请参阅
- Unix 上的 getFolderPath 行为 
适用于
GetFolderPath(Environment+SpecialFolder, Environment+SpecialFolderOption)
- Source:
- Environment.cs
- Source:
- Environment.cs
- Source:
- Environment.cs
使用用于访问特殊文件夹的指定选项获取指定系统特殊文件夹的路径。
public:
 static System::String ^ GetFolderPath(Environment::SpecialFolder folder, Environment::SpecialFolderOption option);public static string GetFolderPath (Environment.SpecialFolder folder, Environment.SpecialFolderOption option);static member GetFolderPath : Environment.SpecialFolder * Environment.SpecialFolderOption -> stringPublic Shared Function GetFolderPath (folder As Environment.SpecialFolder, option As Environment.SpecialFolderOption) As String参数
- folder
- Environment.SpecialFolder
标识系统特殊文件夹的枚举值之一。
枚举值之一,指定用于访问特殊文件夹的选项。
返回
指定系统特殊文件夹的路径(如果计算机上存在该文件夹);否则为空字符串(“)。
如果操作系统未创建该文件夹、删除现有文件夹或文件夹是虚拟目录(如“我的计算机”),则文件夹将不存在于物理路径。
例外
当前平台不受支持。
注解
此方法检索系统特殊文件夹的路径,例如 Program Files、Programs、System 或 Startup,可用于访问通用信息。 在安装 Windows 版本时,系统默认或由用户显式设置特殊文件夹。
              folder 参数指定要检索的特殊文件夹,并且必须是 Environment.SpecialFolder 枚举中的值之一;任何其他值都引发异常。
有关特殊文件夹的详细信息,请参阅 常量特殊项 ID 列表(CSIDL)。
另请参阅
- Unix 上的 getFolderPath 行为