如何将xml文件作为资源添加到Windows窗体exe

Vin*_*nod 5 c# xml winforms

我有一个Windows窗体C#应用程序.我想将xml文件添加到此.exe此xml文件必须是.exe文件的一部分.我该怎么做?如何访问程序中的xml文件.

我试过的是这个:

Stream st = Assembly.GetExecutingAssembly().GetManifestResourceStream("CApp.xmlfile.xml");
StreamReader reader = new StreamReader(st);

doc = XElement.Load(reader);
Run Code Online (Sandbox Code Playgroud)

xml文件的构建操作是"嵌入式资源"

Chu*_*age 6

在要添加到项目的属性中,转到"资源" - >"添加资源"(向下箭头)添加现有文件.

然后根据需要命名.

然后,您将在项目的解决方案中看到它 - > Properties(文件夹)Resources.Designer.cs文件.要加载它,请说您将资源(文件)命名为CAppxmlfile.

你加载它 XElement resource = XElement.Parse(Properties.Resources.CAppxmlfile);