Updating an XML file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dexterous22
    New Member
    • Jun 2007
    • 8

    Updating an XML file

    hey ..
    I can update update my XML File .. but every time i want to update it .. I must change in the code .. can't I change it through a form ? Text box .. and afterfinishing pressing a button .. ??
    this is my code : <script runat="server">

    void Page_Load(objec t sender, System.EventArg s e){
    if(!Page.IsPost Back){
    XmlDocument xmlDoc = new XmlDocument();
    xmlDoc.Load(Ser ver.MapPath("XM LFile.xml"));

    XmlNodeList nodeList = xmlDoc.SelectNo des("/CategoryList/Category[@ID='01']");

    nodeList[0].ChildNodes[0].InnerText = "Whatever";
    nodeList[0].ChildNodes[1].InnerText = "Nevermind" ;
    nodeList[0].ChildNodes[2].InnerText = "false";
    xmlDoc.Save(Ser ver.MapPath("XM LFile.xml"));
    Response.Write( "XML File updated!");
    }
    }
    </script>

    Thanks .. please help
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    Welcome to TSDN. You can modify xml through ado.net. HTH.

    Comment

    • Dexterous22
      New Member
      • Jun 2007
      • 8

      #3
      Thanks but I actully want to do this through web page ..
      I putted the code that updates an xml file in function :
      void updateclick(obj ect sender, System.EventArg s e)

      i just wanna know how can i call this function through a button ..

      Comment

      • TRScheel
        Recognized Expert Contributor
        • Apr 2007
        • 638

        #4
        Originally posted by Dexterous22
        Thanks but I actully want to do this through web page ..
        I putted the code that updates an xml file in function :
        void updateclick(obj ect sender, System.EventArg s e)

        i just wanna know how can i call this function through a button ..

        You can attach the button's onclick event to the function. Should be something like this ( i would put this in the OnPageLoad function )

        XMLUpdateButton .OnClick += new EventHandler(up dateclick);

        Comment

        • Dexterous22
          New Member
          • Jun 2007
          • 8

          #5
          thanks .. actully it didn't work ..but thanks anyway

          Comment

          • TRScheel
            Recognized Expert Contributor
            • Apr 2007
            • 638

            #6
            Originally posted by Dexterous22
            thanks .. actully it didn't work ..but thanks anyway

            The code didnt fire with the on click? or the write to xml didnt work? If the code didnt fire, make sure the button in question does a postback.

            Comment

            • Dexterous22
              New Member
              • Jun 2007
              • 8

              #7
              that page doesn't load ...
              this is the error I get be .Net debugger :
              Compiler Error Message: CS0122: 'System.Web.UI. WebControls.But ton.OnClick(Sys tem.EventArgs)' is inaccessible due to its protection level

              thanks

              Comment

              • Dexterous22
                New Member
                • Jun 2007
                • 8

                #8
                that page doesn't load ...
                this is the error I get be .Net debugger :
                Compiler Error Message: CS0122: 'System.Web.UI. WebControls.But ton.OnClick(Sys tem.E ventArgs)' is inaccessible due to its protection level

                Line 44: void Page_Load()
                Line 45: {
                Line 46: XMLUpdateButton .OnClick += new EventHandler(on UpdateFn);
                Line 47:
                Line 48: }


                i attached it to the onpage load function .. but it didn't work .. ? do u see any error in the way i wrote it ?
                please help

                Comment

                Working...