如何保存从代码修改的项目资源 [英] How to save a project resource modified from code

查看:87
本文介绍了如何保存从代码修改的项目资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加了一个xml作为项目资源(从 Project-> Project Properties-> Resources Tab-> AddResource-> AddExistingFile-> AddExistingFile->中选择了MyResource.xml



我一直在显示这个文件的内容,因为它是一个普通的XDocument



I have added a xml as a project resource (the ones that are been added from Project->Project Properties->Resources Tab->AddResource->AddExistingFile-> Select MyResource.xml)

I have been displaying the content of this file as it was a regular XDocument

XDocument _xDoc = XDocument.Parse(MyApp.Properties.Resources.MyResource);





现在如果我已经在_xDoc中添加了新元素(或删除旧元素)我想在MyResource.xml文件中记录这些更改。

通常我会这样做:





Now if I have added new elements (or remove old ones) from the _xDoc I want to record those changes also in MyResource.xml file.
Normally I will do it with :

public  void  SaveMofifiedDoc(XElement  _new){
 _xDoc.Element(TAG).Add( _new);
_xDoc.Save("DocPath");
}



我正在寻找类似的东西:




I am looking for something like:

public  void  SaveMofifiedDoc(XElement _new) {
 _xDoc.Element(TAG).Add( _new);
MyApp.Properties.Resources.MyResource.Save(_xDoc)
}





我用Google搜索,我看到了这个并不是那么容易,也许我必须使用流,但我没有看到任何适合我想要的例子。



I googled and I see this is not that easy , maybe I have to use streams but I didn't saw any example that suits what I want.

推荐答案

项目资源无意修改在运行时并保存回来;因为这些资源在编译期间被集成到文件中。



如果你想在运行时修改xml文件并保存更改,那么坚持使用它的xml文件拥有,你随时都可以阅读和写作。
Project resources are not meant to be modified at runtime and saved back ; because such resources are integrated to the file during compilation.

If you want to modify the xml file at runtime and save the changes, then stick with an xml file of its own, that you will be able to read and write at any time.


这篇关于如何保存从代码修改的项目资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆