<?xml version="1.0" encoding="UTF-8"?> <AlbumFolder> <Album Name="A"> <ImagesFolder>D:\OrgWebsite\A\Images</ImagesFolder> <Album> <VideosFolder>D:\OrgWebsite\A\Videos</VideosFolder> </Album> </Album> </AlbumFolder>
<?xml version="1.0" encoding="UTF-8"?> <AlbumFolder> <Album Name="A"> <ImagesFolder>D:\OrgWebsite\A\Images</ImagesFolder> <VideosFolder>D:\OrgWebsite\A\Videos</VideosFolder> </Album> </AlbumFolder>
public void vdoxml() { string subPath = txtalbum.Text; XmlDocument xmldoc = new XmlDocument(); XmlNode VideosFolder = xmldoc.CreateElement("VideosFolder"); XmlNode albumnode = xmldoc.CreateElement("AlbumFolder"); XmlNode album = xmldoc.CreateElement("Album"); string path = Server.MapPath("") + "\\" + txtalbum.Text + "\\" + "Videos"; string imglocation = Server.MapPath("~/") + "XML/"; bool isExists = System.IO.Directory.Exists(Server.MapPath(subPath)); if (!isExists) { DirectoryInfo di = new DirectoryInfo(Server.MapPath("~/") + "XML/"); FileInfo[] TXTFiles = di.GetFiles("*.xml"); if (TXTFiles.Length == 0) { XmlNode docNode = xmldoc.CreateXmlDeclaration("1.0", "UTF-8", null); xmldoc.AppendChild(docNode); XNamespace adlcp = "http://www.w3.org/2001/XMLSchema-instance"; xmldoc.AppendChild(albumnode); XmlAttribute albumattribute1 = xmldoc.CreateAttribute("Name"); albumattribute1.Value = txtalbum.Text; album.Attributes.Append(albumattribute1); VideosFolder.InnerText = path; albumnode.AppendChild(album); album.AppendChild(VideosFolder); xmldoc.Save(Server.MapPath("" + "~/" + "XML/album.xml")); } else { xmldoc.Load(Server.MapPath("~/" + "XML/album.xml")); int flgnode = 0; if (flgnode == 0) { XmlAttribute albumattribute1 = xmldoc.CreateAttribute("Name"); albumattribute1.Value = txtalbum.Text; album.Attributes.Append(albumattribute1); VideosFolder.InnerText = path; albumnode.AppendChild(album); album.AppendChild(VideosFolder); XmlNodeList lstxmlNode = xmldoc.GetElementsByTagName("AlbumFolder"); lstxmlNode[0].AppendChild(album); xmldoc.Save(Server.MapPath("~/" + "XML/album.xml")); } } }//if album folder already exists. else { xmldoc.Load(Server.MapPath("~/" + "XML/album.xml")); int flgsubnode = 0; XmlNodeList nodelist = xmldoc.GetElementsByTagName("Album"); for (int i = 0; i < nodelist.Count; i++) { string anode = nodelist[i].Attributes["Name"].Value; if (txtalbum.Text.Equals(anode)) { flgsubnode = 1; VideosFolder.InnerText = path; albumnode.AppendChild(album); album.AppendChild(VideosFolder); nodelist = xmldoc.GetElementsByTagName("Album"); nodelist[i].AppendChild(album); xmldoc.Save(Server.MapPath("~/" + "XML/album.xml")); // Response.Write(txtalbum.Text + " Is already Present. Please Choose Another"); } } if (flgsubnode == 0) { VideosFolder.InnerText = path; albumnode.AppendChild(album); album.AppendChild(VideosFolder); XmlNodeList lstxmlNode = xmldoc.GetElementsByTagName("Album"); lstxmlNode[0].AppendChild(album); xmldoc.Save(Server.MapPath("~/" + "XML/album.xml")); } //xmldoc.Load(Server.MapPath("~/" + "XML/album.xml")); //VideosFolder.InnerText = path; //albumnode.AppendChild(album); //album.AppendChild(VideosFolder); //XmlNodeList lstxmlNode = xmldoc.GetElementsByTagName("Album"); //lstxmlNode[0].AppendChild(album); //xmldoc.Save(Server.MapPath("~/" + "XML/album.xml")); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)