Home > DeveloperSection > Forums > Error while loading string to xml document in windows c#
jayprakash sharma
jayprakash sharma

Total Post:117

Points:821
Posted on    May-10-2013 2:16 AM

 C# C# 
Ratings:


 1 Reply(s)
 1259  View(s)
Rate this:
Hi Expert!

I have an application where it reads the xml data, makes some changes and saves it into a word document. When i run the app 1st time the base URI is "C:\Documents

\Visual Studio 2010\Projects\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug". But when i run the second time without restarting the app the base URI 

changes to last saved location ans i get an error saying the xml file not found.Below is the part of code. Where am I gng wrong

 string xmlSource = string.Empty;

            if (string.IsNullOrEmpty(xmlSource))
                xmlSource = "Dictionary.xml";
                XmlDocument doc = new XmlDocument();
                doc.Load(xmlSource);
                FileStream usrFs = null;
            try
            {
                usrFs = new FileStream(xmlSource, FileMode.Open, FileAccess.Read,
                                 FileShare.ReadWrite);
            }

            catch (IOException ex)
            {
                MessageBox.Show(ex.Message);
            }
            try
            {
                doc.Load(usrFs);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
   
Thanks in advance! 



AVADHESH PATEL

Total Post:604

Points:4228
Posted on    May-10-2013 9:12 AM

Hi!

Try as following 

Use full path rather than relative path.

xmlSource = System.AppDomain.CurrentDomain.BaseDirectory + "\\Dictionary.xml";

I hope it helpful for you!

Don't want to miss updates? Please click the below button!

Follow MindStick