简体   繁体   中英

Where should I store my App specific config files in WPF

Background : I have some Application Data. ie the Database, come important config files. This data is vital for the application to start else it is exited.

Problem : Where should I store this data. ie in which folder and where. Right Now (This is wrong) it is stored in a folder in Debug/App_Data. But is causing issues in git and when we publish the App the data is not found. So where can we store this folder ?

Present Structure is "WpfApplication2\\WpfApplication2\\bin\\Debug"

These Files need to be present when the app is started. So they need to be a part of the app itself.

Would suggest use:

var pathToConfig = Path.Combine( System.Environment.GetFolderPath(
           Environment.SpecialFolder.CommonApplicationData), YOUR_APP_NAME);

On Windows Vista and + machine this will end in "C:\\ProgramData\\AllUser\\YOUR_APP_NAME"

On Windows XP "C:\\Document and Settings\\Application Data\\YOUR_APP_NAME"

in both cases, you guaranteed by OS itself to have write permission in these location, and its "hidden" from the users eyes (both folders are hidden by default)

As @Athari correctly suggests: YOUR_APP_NAME should be YOUR_COMPAMY_NAME\\YOUR_APP_NAME

You can save your application specific files at

Path.Combine(Environment.GetFolderPath(
    Environment.SpecialFolder.LocalApplicationData),
    Path.GetFileNameWithoutExtension(AppDomain.CurrentDomain.FriendlyName));

but you can use other folders like My Documents too.

Edit: I've remembered I have used Isolated Storage in a WPF app back in .NET 3.0 (I think):

Introduction to Isolated Storage

Performing Isolated Storage Tasks

将那些文件包括到您的项目中,并将属性“ Copy to Output directoryCopy always

您的App.config应该位于.NET桌面应用程序的常规位置:它应该是yourApplication .exe.config与.exe在同一文件夹中。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM