I have a WPF .NET Framework 4.7.2 app that uses the UserScopedSetting attribute class to save custom settings to the users AppData\Local folder. On my development machine, the path to my user.config file looks like the following: "C:\Users\Me\AppData\Local\MyCompanyName\MyAppName.exe_Url_rtcpnmh0iltfii1p24rpamavswwh2yll\1.0.7321.1900\user.config".
My app also uses NLog for logging, and .json files for storing application data. Those types of files are currently stored in the application directory, but I want to move them to AppData\Local. My preference is to store them in the same folder that contains user.config.
I know how to programmatically get the path to my AppData\Local\EvanscoApps folder, but I do not know how to find "\MyAppName.exe_Url_rtcpnmh0iltfii1p24rpamavswwh2yll". Where does that come from, and how can I access or build it with code?
In the following pseudo code, how should I modify the "get;" for the AppUrlThingy property?
public class LocalDataLocator
{
public string DataLocation { get; set; }
public LocalDataLocator()
{
DataLocation = GetFolderBase();
}
private string LocalFolder { get; }
private string AppCompany
{
get
{
var asm = Assembly.GetEntryAssembly();
var attr = asm.GetCustomAttributes(typeof(AssemblyCompanyAttribute), true);
return attr.Length > 0 ? ((AssemblyCompanyAttribute) attr[0]).Company : null;
}
}
private Version AppFileVersion
{
get
{
var asm = Assembly.GetEntryAssembly();
var attrFileVersion = asm.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true);
return new Version(((AssemblyFileVersionAttribute) attrFileVersion[0]).Version);
}
}
private ??? AppUrlThingy
{
get
{
????????
}
}
private string GetFolderBase()
{
var folderBase = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
var appCompany = AppCompany;
var appFileVersion = AppFileVersion;
var appUrlThingy = AppUrlThingy;
return $@"{folderBase}\{appCompany}\{appUrlThingy}\{appFileVersion}";
}
}