Environment.GetFolderPath 方法

获取指向由指定枚举标识的系统特殊文件夹的路径。

**命名空间:**System
**程序集:**mscorlib(在 mscorlib.dll 中)

语法

声明
Public Shared Function GetFolderPath ( _
    folder As SpecialFolder _
) As String
用法
Dim folder As SpecialFolder
Dim returnValue As String

returnValue = Environment.GetFolderPath(folder)
public static string GetFolderPath (
    SpecialFolder folder
)
public:
static String^ GetFolderPath (
    SpecialFolder folder
)
public static String GetFolderPath (
    SpecialFolder folder
)
public static function GetFolderPath (
    folder : SpecialFolder
) : String

参数

  • folder
    标识系统特殊文件夹的枚举常数。

返回值

如果指定系统的特殊文件夹实际存在于您的计算机上,则为到该文件夹的路径;否则为空字符串 ("")。 如果系统未创建文件夹、已删除现有文件夹,或者文件夹是不对应物理路径的虚拟目录(例如“我的电脑”),则该文件夹不会实际存在。

异常

异常类型 条件

ArgumentException

folder 不是 System.Environment.SpecialFolder 的成员。

备注

此方法检索指向系统特殊文件夹(如 Program Files、Programs、System 或 Startup)的路径,可用于访问公共信息。特殊文件夹在默认情况下由系统设置,或者由用户在安装 Windows 的某个版本时显式进行设置。

folder 参数指定要检索的特殊文件夹,且该参数必须是 Environment.SpecialFolder 枚举中的一个值;任何其他值都将引发异常。

有关特殊文件夹的更多信息,请参见 https://msdn.microsoft.com/library/en-us/shellcc/platform/Shell/reference/enums/csidl.asp 中的 CSIDL Values 主题。

示例

' Sample for the Environment.GetFolderPath method
Imports System

Class Sample
   Public Shared Sub Main()
      Console.WriteLine()
      Console.WriteLine("GetFolderPath: {0}", Environment.GetFolderPath(Environment.SpecialFolder.System))
   End Sub 'Main
End Class 'Sample
'
'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
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
*/

.NET Framework 安全性

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0

请参见

参考

Environment 类
Environment 成员
System 命名空间