How I use XDocument.Load() to get a file in the application directory

前端 未结 2 564
没有蜡笔的小新
没有蜡笔的小新 2021-01-19 01:57

I have a XML file in a folder in the project. I would like to use XDocument.Load(string) but do I have to write the complete path to the application as part of

2条回答
  •  一生所求
    2021-01-19 02:50

    It would be better to add your XML file as a project resource: go to the properties of the project then to Resources tab. Choose Add Resource and add your file. Then you will be able to get your XDocument that way:

    XDocument xml = XDocument.Parse(Properties.Resources.Registro);
    

    If you want, however, to keep everything like you did you could maybe go with Reflection. See the answer here: How to read embedded resource text file

提交回复
热议问题