// .NET 4.0 implementation of System.Environment.GetFolderPath method public static String GetFolderPath(SgiSpecialFolder folder, SgiSpecialFolderOption option) { if (!Enum.IsDefined(typeof(SgiSpecialFolder), folder)) throw new ArgumentException(String.Format(CultureInfo.InvariantCulture, "Illegal enum value: {0}.", (Int32)folder)); if (!Enum.IsDefined(typeof(SgiSpecialFolderOption), option)) throw new ArgumentException(String.Format(CultureInfo.InvariantCulture, "Illegal enum value: {0}.", (Int32)option)); if (option == SgiSpecialFolderOption.Create) new FileIOPermission(PermissionState.None) { AllFiles = FileIOPermissionAccess.Write }.Demand(); StringBuilder lpszPath = new StringBuilder(260); // MAX_PATH (260) Int32 num = SafeNativeMethods.SHGetFolderPath(IntPtr.Zero, (Int32)(folder | ((SgiSpecialFolder)((Int32)option))), IntPtr.Zero, 0, lpszPath); if (num < 0) { switch (num) { case -2146233031: // COR_E_PLATFORMNOTSUPPORTED (0x80131539) throw new PlatformNotSupportedException(); } } String path = lpszPath.ToString(); new FileIOPermission(FileIOPermissionAccess.PathDiscovery, path).Demand(); return path; }
// .NET 4.0 implementation of System.Environment.GetFolderPath method public static String GetFolderPath(SgiSpecialFolder folder) { return SgiUtils.GetFolderPath(folder, SgiSpecialFolderOption.None); }