Skip to content

Instantly share code, notes, and snippets.

@fredgdaley2
Created February 22, 2017 01:46
Show Gist options
  • Save fredgdaley2/a6aa03d02b8fd17504206157ee295938 to your computer and use it in GitHub Desktop.
Save fredgdaley2/a6aa03d02b8fd17504206157ee295938 to your computer and use it in GitHub Desktop.
.NET Framework => Core: Getting The App Data Folder
//Credit goes to this blog post https://dotnettips.wordpress.com/2017/02/20/net-framework-core-getting-the-app-data-folder/
//For .Net Core
public static string AppDataFolder()
{
var userPath = Environment.GetEnvironmentVariable(
RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ?
"LOCALAPPDATA" : "Home");
var assy = System.Reflection.Assembly.GetEntryAssembly();
var companyName = assy.GetCustomAttributes<AssemblyCompanyAttribute>()
.FirstOrDefault();
var path = System.IO.Path.Combine(userPath, companyName.Company);
return path;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment