22

I have an ASP.Net Core application, and for the current purposes I've got to use LocalAppData.

Usually I would write Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), but unfortunately it's not working with ASP.Net Core.

Could anyone help me with this?

UPDATE

Thanks to Adem Caglin, I've found the solution.

The code I use:

Environment.GetEnvironmentVariable( RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "LocalAppData" : "Home");

Dmitry Volkov
  • 1,347
  • 1
  • 18
  • 33

2 Answers2

17

Try this:

Environment.GetEnvironmentVariable("LocalAppData");

ps: tested on windows

adem caglin
  • 22,700
  • 10
  • 58
  • 78
  • thanks a lot! but before I accept your answer, I've got to ask if there is some kind of workaround with Linux, which does not contain enviromental variable "LocalAppData". I thought about checking OS, and depending on it return either "LocalAppData" or "Home", but guess what? ASP.Net Core does not contain definition for Enviroment.OSVersion -_- – Dmitry Volkov Aug 31 '16 at 07:06
  • 1
    Getting variable for runtime platform might be a solution. See http://stackoverflow.com/questions/39207282/how-to-get-information-about-runtime-net-core – adem caglin Aug 31 '16 at 07:18
  • 6
    `Environment.GetEnvironmentValiable( RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "ProgramData" : "Home" );` or `"LocalAppData"` or `"AllUsersProfile"` On windows they are all good to check out. On Linux, `"HOME"` is about all you can count on. – Jesse Chisholm Jan 17 '18 at 22:40
6

Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)

Filipe Carneiro
  • 448
  • 5
  • 5