Skip to content

Instantly share code, notes, and snippets.

@metametaclass
Created December 15, 2012 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save metametaclass/4294569 to your computer and use it in GitHub Desktop.
Save metametaclass/4294569 to your computer and use it in GitHub Desktop.
Environment.GetFolderPath
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