Click here to Skip to main content
12,449,098 members (52,293 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET XML
Hi,

I am working in a asp.net 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="http://www.google.com">
               <title>hi1</title>
               <description>Demo</description>
               </photo>
</photos>

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

1 solution

Rate this: bad
 
good
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();
        XD.Load(xmlFilePath);
        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;
        XD.Save(xmlFilePath);
    }
Use this code...
it does what exactly you want. Make sure you dont get error at XD.Load
  Permalink  
v2
Comments
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
Web01 | 2.8.160811.3 | Last Updated 20 Nov 2012
Copyright © CodeProject, 1999-2016
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