Error while updating XML thru C#.Net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • VijaySofist
    New Member
    • Jun 2007
    • 107

    Error while updating XML thru C#.Net

    Hi All,

    I have written a procedure in C#.Net for updating an xml node. I am using VS2008 with Dot Net Framework 3.5

    I am submitting my code in below

    Code:
     private void updateNodeValue(string nodename, string nodevalue, string strfilepath)
             {
                 try
                 {
                     XmlDocument xd1 = new XmlDocument();
                     xd1.Load(strfilepath);
                     string selnode = xmlnodepath + "/" + nodename;
                     XmlNode nod1 = xd1.SelectSingleNode(selnode);
                     nod1.InnerText = nodevalue;
                     xd1.Save(strfilepath);
                     MessageBox.Show("Successfully Updated");
                 }
                 catch (Exception ex)
                 {
                     MessageBox.Show(ex.Message);
                 }
             }

    Now What the problem is, it throws an error "Object reference not set". I don't know exactly why and where the error occurs


    With Regards
    Vijay. R
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    In Visual Studio, under the Debug menu is an option "Exceptions ".
    Tick the box for "thrown" on for "Common Language Runtime exceptions" so it is on. This will cause Visual Studio to halt and highlight the error-producing line when the error is created instead of later when it goes unhandled.

    Comment

    Working...