Click here to Skip to main content
11,921,491 members (70,630 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# ASP.NET XML

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 23: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
0 OriginalGriff 578
1 Dave Kreskowiak 285
2 Sergey Alexandrovich Kryukov 173
3 phil.o 160
4 Richard MacCutchan 155
0 OriginalGriff 7,036
1 KrunalRohit 4,530
2 Sergey Alexandrovich Kryukov 3,286
3 George Jonsson 2,840
4 Suvendu Shekhar Giri 2,216

Advertise | Privacy | Mobile
Web04 | 2.8.151120.1 | Last Updated 20 Nov 2012
Copyright © CodeProject, 1999-2015
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