从Resources.resx读取.xml文件 [英] Read a .xml file from Resources.resx

查看:72
本文介绍了从Resources.resx读取.xml文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将.xml文件添加到应用程序资源.
现在,我想访问该xml文件并使用c#.net
中的该xml文件填充数据集.
谁能帮忙我如何在C#.net

I have added a .xml file to application resources.
Now I want to access that xml file and fill dataset using that xml file in c#.net

Can anyone help that how can i do this in C#.net

推荐答案

中进行一些细致的搜索:

A little googling goes a LONG way:

XDocument doc = XDocument.Parse(MyProject.Properties.Resources.XMLFile);


如果您使用.RESX资源,它将创建两个文件为你.查看生成的C#类.永远不要触摸它,它会在您每次更改资源中的任何内容时自动生成.找到生成的静态类和静态属性;属性名称应与XML文件名相同或接近.使用此属性,它将代表文件的内容.使用此变量(别无其他;不要通过Resource Manager手动检索资源-已经为您完成了).

要填充数据集,请将文件的内容视为字符串资源.您可以使用System.Xml.XmlReader进行读取,从中创建XML文档,等等.

—SA
If you use .RESX resource it will create two files for you. Look at the generated C# class. Never touch it, it will be auto-generated every time you change anything in the resources. Locate the generated static class and static property; the property name should be the same or close to the XML file name. Use this property, it will represent the content of the file. Use this variable (and nothing else; don''t retrieve resource manually via Resource Manager — it''s already done for you).

To fill a dataset, treat the content of the file as a string resource. You can read it with System.Xml.XmlReader, create XML document out of it, etc.

—SA


我得到了完美的答案.
这是代码

I got the perfect Answer for it.
Here it is the code

DataSet ds = new DataSet();
   XDocument doc = XDocument.Parse(Namespace.Properties.Resources.Name);
   ds.ReadXml(doc.CreateReader());


这篇关于从Resources.resx读取.xml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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