Click here to Skip to main content
15,894,740 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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


HTML
<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

1 solution

C#
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
 
Share this answer
 
v2
Comments
Raghavanand 20-Nov-12 6:19am    
Thank you for the reply sir !! do i need to enter this on button click
[no name] 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900