By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
462,232 Members | 630 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 462,232 IT Pros & Developers. It's quick & easy.

Updating an XML file

P: 8
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(object sender, System.EventArgs e){
if(!Page.IsPostBack){
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(Server.MapPath("XMLFile.xml"));

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

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

Thanks .. please help
Jun 12 '07 #1
Share this Question
Share on Google+
7 Replies

kenobewan
Expert 2.5K+
P: 4,871
Welcome to TSDN. You can modify xml through ado.net. HTH.
Jun 12 '07 #2

P: 8
Thanks but I actully want to do this through web page ..
I putted the code that updates an xml file in function :
void updateclick(object sender, System.EventArgs e)

i just wanna know how can i call this function through a button ..
Jun 12 '07 #3

TRScheel
Expert 100+
P: 638
Thanks but I actully want to do this through web page ..
I putted the code that updates an xml file in function :
void updateclick(object sender, System.EventArgs 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(updateclick);
Jun 12 '07 #4

P: 8
thanks .. actully it didn't work ..but thanks anyway
Jun 12 '07 #5

TRScheel
Expert 100+
P: 638
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.
Jun 12 '07 #6

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

thanks
Jun 13 '07 #7

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

Line 44: void Page_Load()
Line 45: {
Line 46: XMLUpdateButton.OnClick += new EventHandler(onUpdateFn);
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
Jun 13 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.