如何添加一个XML文件到Windows资源构成的exe [英] How to add an xml file as a resource to Windows Forms exe
问题描述
我有一个Windows窗体C#应用程序。
我想一个xml文件添加到该.exe文件
这个XML文件必须是.exe文件的一部分。
我怎么能做到这一点,我怎么能访问该程序的XML文件
I have a Windows forms C# application. I want to add an xml file to this .exe This xml file must be part of the .exe file. How can I do that and how can I access the xml file in the program.
我曾尝试是这样的:
Stream st = Assembly.GetExecutingAssembly().GetManifestResourceStream("CApp.xmlfile.xml");
StreamReader reader = new StreamReader(st);
doc = XElement.Load(reader);
生成操作XML的文件是嵌入的资源
Build Action for xml file is "Embedded Resource"
推荐答案
在你想将它添加到,进入资源项目的属性 - >添加资源(向下箭头)添加现有文件
In the properties of the project you want to add it to, go to the Resources -> Add Resource (down arrow) add existing file.
然后,不过你想要它命名为
Then name it however you want.
然后你就会看到它在你的项目的解决方案 - >属性(文件夹)资源。 Designer.cs文件。加载它,说你命名的资源(文件)CAppxmlfile。
Then you'll see it in the solution in your project -> Properties (folder) Resources.Designer.cs file. To load it, say you named the resource(the file) CAppxmlfile.
您与的XElement资源= XElement.Parse(Properties.Resources加载它.CAppxmlfile);
这篇关于如何添加一个XML文件到Windows资源构成的exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!