Search code examples
c#xmlxmldocument

error- Data at the root level is invalid Line 1 position 1.


Please check the code. I'm getting this error even after using doc.Load() function.

Application.DoEvents();
XmlDocument xmldoc = new XmlDocument();
XmlNodeList xmlnode;
FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read);
xmldoc.Load(fs); 
xmlnode = xmldoc.GetElementsByTagName("Source");

Check the code in : https://pastebin.com/4U7qa1L4


Solution

  • Remove all the extra hidden files from XML folder. It should not contain any files other than ".xml". Also you have to use xmlfile.Load() instead of xmlfile.xmlLoad().