Created
December 15, 2012 12:49
-
-
Save metametaclass/4294569 to your computer and use it in GitHub Desktop.
Environment.GetFolderPath
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static string GetFolderPath(Environment.SpecialFolder folder) | |
{ | |
if (!Enum.IsDefined(typeof(Environment.SpecialFolder), folder)) | |
{ | |
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Arg_EnumIllegalVal"), new object[] | |
{ | |
(int)folder | |
})); | |
} | |
StringBuilder stringBuilder = new StringBuilder(260); | |
Win32Native.SHGetFolderPath(IntPtr.Zero, (int)folder, IntPtr.Zero, 0, stringBuilder); | |
string text = stringBuilder.ToString(); | |
new FileIOPermission(FileIOPermissionAccess.PathDiscovery, text).Demand(); | |
return text; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment