Reputation:
First of all I have to precise that I am Web developer. But face to a problem I was obliged to create an exe in WPF as simple it can sound with small datas stored in a XML file
.
The problem came after installation. I followed the rules but my WPF can't write in the XML file. I see that is permission because when I put all the folder installation in let's say D drive. I don't have any problem writing in the XML file.
So How can I write in the XML file after installation in any client machine? Have I to add some instructions?
Upvotes: 0
Views: 1147
Reputation: 805
Since Windows 7, the default user has no administrative rights. So applications are not allowed to write in programs directory (c:\Programs\myApp), cause they are executed with user rights as default. Application data should be stored in users directory (e.g. c:\user\fred\AppData\Local).
You can get the directory easy be using the Environment.SpecialFolder-Enumeration:
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
Upvotes: 4
Reputation: 353
You can't save to Program Files on windows 7+. Instead you can create a folder in the AppData area. I use this to get an application directory
public static string GetAppDataDir(string company, string appName)
{
string appDataDir = Environment.ExpandEnvironmentVariables( "%APPDATA%" );
string appDir = Path.Combine( appDataDir, company );
appDir = Path.Combine( appDir, appName );
if (!Directory.Exists(appDir))
Directory.Create(appDir);
return appDir;
}
Upvotes: 1