为什么即使我下次启动程序时看到更新的值,为什么也没有保存我的XML文件? [英] Why isn't my XML file being saved, even though the program sees the updated values next time I start it?
问题描述
我正在读取XML文件的内容并将其解析为对象模型.
I'm reading the contents of an XML file and parsing that into an object model.
当我修改对象模型中的值时,请使用以下代码将其保存回xml:
When I modify the values in the object model, then use the following code to save it back to the xml:
XElement optionXml = _panelElement.Elements("options").FirstOrDefault();
optionXml.SetAttributeValue("arming", value.ToString());
_document.Save(_fileName);
据我所知,这是可行的,因为当我关闭应用程序并重新启动它时,我下次保存的值将反映在对象模型中.
This works, as far as I can see, because when I close the application and restart it the values that I had saved are reflected in the object model next time I view it.
但是,当我加载实际的XML文件时,这些值仍保持原始状态.
However, when I load the actual XML file, the values are still as they were originally.
这是为什么?要使用新值保存实际的XML文件,我该怎么做?
Why is this? What do I need to do to save the actual XML file with the new values?
推荐答案
Basically what this means is that you are saving your file, just not where you think you're saving it. For example, you might think that you are saving to C:\Program Files\Your App\yourFile.xml
, but what is happening under the hood is that the OS is silently redirecting that to %APPDATA%\Your App\yourFile.xml
. When you go to reload it, once again the OS silently redirects from that location.
这是一种安全措施,旨在更好地封装应用程序及其数据,并防止未经授权的写入可能会损坏的位置.您仍然可以强制将保存保存为%PROGRAMFILES%\Your App
,但是为此,您要么需要放宽应用于该文件夹的ACL,要么需要提高应用程序运行时的特权级别.
This is a security measure designed to better encapsulate applications and their data and to prevent unauthorised writes to locations where damage can occur. You can still force a save to %PROGRAMFILES%\Your App
, but to do that you either need to relax the ACLs applied to that folder, or you need to elevate the privilege level your application runs at.
这篇关于为什么即使我下次启动程序时看到更新的值,为什么也没有保存我的XML文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!