[英]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应用程序中使用过隔离存储(我认为):
将那些文件包括到您的项目中,并将属性“ Copy to Output directory
为Copy always
您的App.config应该位于.NET桌面应用程序的常规位置:它应该是yourApplication .exe.config与.exe在同一文件夹中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.