Reading embedded XML file c#

后端 未结 6 983
春和景丽
春和景丽 2020-11-27 13:07

How can I read from an embedded XML file - an XML file that is part of a c# project? I\'ve added a XML file to my project and I want to read from it. I want the XML file to

6条回答
  •  一向
    一向 (楼主)
    2020-11-27 13:47

    Set the Build Action to Embedded Resource, then write the following:

    using (Stream stream = typeof(MyClass).Assembly.GetManifestResourceStream("MyNameSpace.Something.xml")) {
        //Read the stream
    }
    

提交回复
热议问题