Skip to content

Instantly share code, notes, and snippets.

@Dehax
Last active April 27, 2017 08:16
Show Gist options
  • Save Dehax/12453905bcd94441f620fc68b64ae577 to your computer and use it in GitHub Desktop.
Save Dehax/12453905bcd94441f620fc68b64ae577 to your computer and use it in GitHub Desktop.
Returns path to the application folder in %LOCALAPPDATA%
private static string _localAppFolderPath = null;
/// <summary>
/// Путь к папке программы в локальной папке пользователя.
/// </summary>
public static string ApplicationFolderPath
{
get
{
if (_localAppFolderPath != null)
{
return _localAppFolderPath;
}
string localAppDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.Create);
StringBuilder sb = new StringBuilder(localAppDataPath);
sb.Append(Path.DirectorySeparatorChar);
Assembly assembly = Assembly.GetExecutingAssembly();
sb.Append(assembly.GetCustomAttribute<AssemblyCompanyAttribute>().Company);
sb.Append(Path.DirectorySeparatorChar);
sb.Append(assembly.GetCustomAttribute<AssemblyProductAttribute>().Product);
sb.Append(Path.DirectorySeparatorChar);
_localAppFolderPath = sb.ToString();
Directory.CreateDirectory(_localAppFolderPath);
return _localAppFolderPath;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment