tags:

views:

57

answers:

1

hi, i have an xml file called image.xml

 <?xml version="1.0"?>

 <Image>
     <Overview>0</Overview>
     <Gallery1>0</Gallery1>
     <Gallery2>0</Gallery2>
 </Image>

code

string strGallery  =textbox1.text;
  lets  say text box  contains value  = Gallery1

when an add an image in the gallery1 using an file upload control when i save the image in the respective folder like: c:\demo\image..

now i should read the above xml file as i have added an image in the gallery1 folder now i should increment that value by "1" because i have added an image to the gallery1 folder.

0 intaiilly which was after adding the image now i should it become 1 like this if i have added an image in the gallery2 folder

then i should incremented <Gallery2>1</Gallery2>. so if next time if i add one more image in gallery2 then the count should be 2

so how can i loop through the elements for the desired gallery becuase if type in my textbox as gallery1 then gallery1 count should be incremetd if type in my textbox as gallery2 then gallery2 count should be incremetd and then save the xml file once modifcation is done .

so how can i achive this functionality thank you

so how can i achive this one

+1  A: 

I'm not sure if I understood it correctly, but try something like this:

XmlDocument xml = new XmlDocument();
xml.LoadXml("<Image>..."); // or xml.Load("yourfile.xml");

string name = "Gallery1";
XmlElement gallery = xml.SelectSingleNode("//" + name) as XmlElement;
if(gallery == null)
{
    gallery = xml.CreateElement(name);
    gallery.InnerText = "1";
    xml.DocumentElement.AppendChild(gallery);
}
 else
{
   gallery.InnerText = (Int32.Parse(gallery.InnerText) + 1).ToString();
}
Rubens Farias
thanks Rubens Farias the abocve code worked for me
prince23