Click here to Skip to main content
13,053,399 members (63,730 online)
Rate this:
Please Sign up or sign in to vote.
See more:

I am working in a application which deals with inserting images into a folder and the path to xml file.So that they are visible in a gallery.I have the xml file. I need to enter the data dynamically to xml file

<pre lang="xml"><photos>
        <photo imageurl="imgs/img 1.jpg" linkurl="">

I would be extremely thankful for sorting this issue
Posted 19-Nov-12 22:55pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

private static void XMLPHOTO(string xmlFilePath,string imgURLVal, string linkURLVal, string titleVal, string descVal )
        XmlDocument XD = new XmlDocument();
        XmlNode Root = XD.SelectSingleNode("//Photos");
        XmlNode Photo = Root.AppendChild(XD.CreateElement("Photo"));
        XmlAttribute PhotAtr1 = Photo.Attributes.Append(XD.CreateAttribute("imageurl"));
        PhotAtr1.InnerText = imgURLVal;
        XmlAttribute PhotAtr2 = Photo.Attributes.Append(XD.CreateAttribute("linkurl"));
        PhotAtr2.InnerText = linkURLVal;
        //Child.InnerText = "Node Innertext";
        XmlNode title = Photo.AppendChild(XD.CreateElement("Title"));
        title.InnerText = titleVal;
        XmlNode desc = Photo.AppendChild(XD.CreateElement("Description"));
        desc.InnerText = descVal;
Use this code...
it does what exactly you want. Make sure you dont get error at XD.Load
Raghavanand 20-Nov-12 6:19am
Thank you for the reply sir !! do i need to enter this on button click
sinhasourabh 20-Nov-12 6:45am
It depend upon your requirement. does your title, desc, etc come from UI ?
In that case you need to call this method in a button click event.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 20 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100