是否可以修改嵌入式资源文件? [英] Is it able to modify a embedded resource file?

查看:68
本文介绍了是否可以修改嵌入式资源文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在资源文件中嵌入了一个xml文件.
在程序代码中,我需要阅读此xml并编辑内容,然后将其保存到Resource文件中.
但是如何将更改后的内容保存到资源文件中?

I embedded a xml file in Resource files.
In programme code, I need to read this xml and edit the content, then save it to Resource file.
But how to save the changed content to Resource files?

推荐答案

嗨基恩,

你不能做到这一点.资源文件以特殊格式编译,并附加在您的应用程序中.请参阅此 http://msdn.microsoft.com/en-us/library /f45fce5x(v=VS.80).aspx .我认为您会发现它很有用.

如果要在运行时编辑xml文件,请不要将其嵌入资源中.将其存储在磁盘上的任何位置并访问该路径.
Hi Kean,

You cant do this. Resource files are compiled in a special format and attached in your application. See this http://msdn.microsoft.com/en-us/library/f45fce5x(v=VS.80).aspx. I think you will find it usefull.

If you want to edit an xml file during runtime, dont embed it in resources. Store it anywhere on your disk and access that path.


您好,我也遇到过同样的问题.我之前也曾在CodeProject上发布过问题,但没有成功.最后,在做了很多谷歌"和书籍之后,我发现的是:

1.您不能编辑嵌入式资源.

2. XML文件不应该像dmageiras所说的那样作为资源保存.所以你可以做的是
a)将其存储在某些磁盘中并访问
或以我的方式做:
b)将XML的构建操作"转换为内容",然后更改复制"
到输出目录"选项以始终复制".
与此相关的XML文件将自动转到debug文件夹,然后
访问XML将更加简单:
加载:
IE.
Hi kean.. i was also having the same problem that you were facing. i had also posted questions on CodeProject earlier but had no success. Finally after doing a lot of "google" and books,what i found is that :

1. You cannot edit an Embedded Resource.

2. The XML file should not be kept as a resource as said by dmageiras. So what you can do is either
a)store it in some disk and access
or do it in my way :
b)make the Build Action of your XML to Content and then change the Copy
to Output Directory option to Copy Always.
with this the XML file will automatically go to the debug folder and
accessing XML will be much simpler:
to Load:
ie.
XmlDocument xmlDoc=new XmlDocument();
      xmlDoc.Load("myXmlFile.Xml");


保存:


to Save:

xmlDoc.Save("myXmlFile.xml");



还建议,如果要编辑任何资源,最好将其保留为内容文件.阅读了许多书籍之后,作者警告说,切勿将您的资源保留为嵌入式资源.

您也可以查看此MSDN链接:
http://msdn.microsoft.com/en-us/library/bbwz4bhx%28v = VS.80%29.aspx

另一个链接将非常有帮助! :
http://forums.silverlight.net/forums/p/152118/339496.aspx

我希望您现在知道正确的方法!

做一个简单的项目,然后尝试做.首次运行项目后,可以在项目的调试文件夹中检入可找到XML的文件夹.通过对该XML的代码进行一些更改,并在XML本身中得到体现.

祝你好运! :)



It is also recommended that if you want to edit any resource, it is better to keep it as Content File. After reading a number of books, the authors have warned that never keep your resource as Embedded Resource.

You can also have a look at this MSDN link :
http://msdn.microsoft.com/en-us/library/bbwz4bhx%28v=VS.80%29.aspx

Another link which will be very helpful! :
http://forums.silverlight.net/forums/p/152118/339496.aspx

I hope now you know what the correct way is!

make a simple project and try to do it. after you run your project for first time, you can check in the debug folder of your project where you can find your XML. make some changes through code on that XML and it gets reflected in that XML itself.

Good Luck! :)


这篇关于是否可以修改嵌入式资源文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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