Created
February 22, 2017 01:46
-
-
Save fredgdaley2/a6aa03d02b8fd17504206157ee295938 to your computer and use it in GitHub Desktop.
.NET Framework => Core: Getting The App Data Folder
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
//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