2

Is there a way to set my app.config for my WCF service so that it outputs to the LocalApplicationData folder without having to hardcode anything?

%LOCALAPPDATA% does not work in XP, and I need to support XP

I have found that shell:Local AppData works, but I am not sure how to put this in an app.config

The next closest I can find is %APPDATA%, but I do not believe this is not the same as LocalApplicationData

Worst case, I can (but would prefer not to) use code to do this (using the SpecialFolders directly), but I am not sure how to set this while keeping the rest of the settings configurable?

Justin Pihony
  • 66,056
  • 18
  • 147
  • 180

2 Answers2

2

You can get it from Environment object.

string path;
path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

Edit according to comment:

Now i understand. You can create your own environment variables to use as part of path in your config.

CMD:

set mylocalapplicationdata="somewhere"

or C#:

string name = "mylocalapplicationdata";
string value = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
Environment.SetEnvironmentVariable(name, value);

After this you can use %mylocalapplicationdata% like other system variables.

You can set variable for one session (process), user, or machine (for machine you need admin permissions).

More information (MSDN): http://msdn.microsoft.com/en-us/library/z46c489x.aspx

Alternatively you can use string like this:

%USERPROFILE%\Local Settings\Application Data

but this is for windows xp only.

Kamil
  • 13,363
  • 24
  • 88
  • 183
1

I don't think there's a way to get the information you want using only built-in environment variables. The information is inconsistent from Windows XP to Windows Vista/7, so I think your best option is to update your config file during installation where you can determine the OS and access other Windows APIs.

Kevin Kibler
  • 13,357
  • 8
  • 38
  • 61
  • Accepting this as all my research points to the impossibility of what I want. So, I had to go to log4net, which allows for a creation of special variables read from code. – Justin Pihony Feb 05 '13 at 15:53