简体   繁体   English

我应该在WPF中将应用程序特定的配置文件存储在哪里

[英]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. 现在(这是错误的),它存储在Debug / App_Data中的文件夹中。 But is causing issues in git and when we publish the App the data is not found. 但是在git中引起问题,并且当我们发布该应用程序时,找不到数据。 So where can we store this folder ? 那么我们可以在哪里存储此文件夹?

Present Structure is "WpfApplication2\\WpfApplication2\\bin\\Debug" 当前结构为“ 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" 在Windows Vista和+机器上,它将以“ C:\\ ProgramData \\ AllUser \\ YOUR_APP_NAME”结尾

On Windows XP "C:\\Document and Settings\\Application Data\\YOUR_APP_NAME" 在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) 在这两种情况下,您都将由OS自己保证在这些位置具有写许可权,并且它们在用户眼中“隐藏”(默认情况下,这两个文件夹都是隐藏的)

As @Athari correctly suggests: YOUR_APP_NAME should be YOUR_COMPAMY_NAME\\YOUR_APP_NAME 正如@Athari正确建议的那样:YOUR_APP_NAME应该是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. 但您也可以使用其他文件夹,例如“ My Documents

Edit: I've remembered I have used Isolated Storage in a WPF app back in .NET 3.0 (I think): 编辑:我记得我曾经在.NET 3.0中的WPF应用程序中使用过隔离存储(我认为):

Introduction to Isolated Storage 隔离存储简介

Performing Isolated Storage Tasks 执行隔离存储任务

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我应该在哪里存储我的 ASP.NET Core 应用程序生产环境的连接字符串? - Where should I store the connection string for the production environment of my ASP.NET Core app? 我应该在Windows Store应用中的共享合同中删除文件 - Where should I delete my file with Share Contract in windows store app 在使用MVVM时,我应该在哪里放置WPF特定代码? - Where should I put WPF specific code when using MVVM? WPF MVVM,我应该在哪里放置视图特定的属性? - WPF MVVM, where should I put view specific properties? WPF / C#:我应该在哪里保存用户首选项文件? - WPF/C#: Where should I be saving user preferences files? 我应该在哪里初始化WPF应用程序的用户帐户? - Where should I initialize the user account of my WPF application? 我应该在哪里更改/设置WPF应用程序中的区域性信息设置,为什么? (必须适用于所有.NET Framework 4.0和更高版本) - Where should I change/set culture info settings in my WPF app and why? (Must works on all .NET frameworks 4.0 and newer) 我应该在哪里存储应用程序的TrayIcon? - Where should I store my application's TrayIcon? 我应该将log4net配置放在哪里-App.config或AppName.dll.log4net? - Where should I put log4net config - App.config or AppName.dll.log4net? 我应该在哪里存储Cookie? - Where should I store a cookie?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM