문제

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?

도움이 되었습니까?

해결책 2

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top