Click here to Skip to main content
15,939,960 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, i have the following codes which allow me to insert data into xml. If i am inserting a second or above data into the xml file it is ok and works fine. But when i wanna insert a first data(which indicated that the xml file is totally empty), it will prompt an error as the title said. Any ideas?

if (xRoot != null)
    xDoc.Load("C:\\Users\\Visual\\Documents\\Visual Studio 2010\\Projects\\FTP Setup\\FTP Setup\\bin\\Debug\\ftpSetup.xml");

    XmlNode importNode = xDoc.ImportNode(xNode1, true);
    XmlNode parentNode = xDoc.SelectSingleNode("FTP_Information");
    parentNode.InsertBefore(xNode1, parentNode.FirstChild);
    xDoc.Save("C:\\Users\\Visual\\Documents\\Visual Studio 2010\\Projects\\FTP Setup\\FTP Setup\\bin\\Debug\\ftpSetup.xml");

1 solution

error says the truth. every valid xml document has a root element where others are under it. possibly it gives this error at line 'xDoc.Save'. if you debug it (start f5, step f10, breakpoint f9) and check xDoc.InnerText, you can see where the error is.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900