I have an asp.net application and I’m using C#. I want to use the XmlDocument.LoadXml() method to read from an .xml file. However, the xml file will not always have the same name so I wanted to pass into the LoadXml() method the path to the file and then read any .xml files that are inside. So, something like this LoadXml(C:\Docs*.xml). It doesn’t work for me. Is there another way I can accomplish this?
Share
You need to separate out the “loading XML from a file” from “picking which file to load”. The two are unrelated concepts. (Although I would point out that
XmlDocument.LoadXmltakes raw XML as a string, not a filename. I think you wantXmlDocument.Load.)What do you want to happen if there’s more than one XML document in
c:\Docs?XmlDocumentcan only load one of them.Use
Directory.GetFiles(@"C:\Docs", "*.xml")to get the list of matching files in the directory. What you should do if there’s more than one of them (or none) is up to you.