public static bool UpdateFileInfoIntoXML(string filename, string foldername, FileProcessStatusEnum status) { try { string absoluteFilePath = GetRootPath() + "\\" + foldername + "\\" + "fi.b"; XmlDocument XD = new XmlDocument(); if (!File.Exists(absoluteFilePath)) { XmlNode xmlnode = XD.CreateNode(XmlNodeType.XmlDeclaration, "", ""); XD.AppendChild(xmlnode); XmlElement Root = XD.CreateElement("BrienzFileInfo"); XD.AppendChild(Root); XD.Save(absoluteFilePath); } XD.Load(absoluteFilePath); if (XD.SelectSingleNode("BrienzFileInfo/FileStatus[@FileName='" + filename + "']") == null) { XmlNode NodeFolder = XD.CreateNode(XmlNodeType.Element, "FileStatus", ""); XmlAttribute AttrFileName = XD.CreateAttribute("FileName"); AttrFileName.Value = filename.Replace("&", "&").Replace("'", "'").Replace("<", "<").Replace(">", ">"); NodeFolder.Attributes.Append(AttrFileName); XmlAttribute AttrFileID = XD.CreateAttribute("FileID"); AttrFileID.Value = Guid.NewGuid().ToString("N"); NodeFolder.Attributes.Append(AttrFileID); XmlAttribute AttrFileCreatedTime = XD.CreateAttribute("FileCreatedTime"); AttrFileCreatedTime.Value = File.GetCreationTime(GetRootPath() + "\\" + foldername + "\\" + filename).ToString(); NodeFolder.Attributes.Append(AttrFileCreatedTime); XmlAttribute AttrFolderName = XD.CreateAttribute("FolderName"); AttrFolderName.Value = foldername; NodeFolder.Attributes.Append(AttrFolderName); XmlAttribute AttrStatus = XD.CreateAttribute("Status"); AttrStatus.Value = status.ToString(); NodeFolder.Attributes.Append(AttrStatus); XD.SelectSingleNode("BrienzFileInfo").AppendChild(NodeFolder); XD.Save(absoluteFilePath); } else { XD.SelectSingleNode("BrienzFileInfo/FileStatus[@FileName='" + filename + "']").Attributes["Status"].Value = status.ToString(); XD.Save(absoluteFilePath); } return(true); } catch (Exception ex) { Console.WriteLine(ex.Message); return(false); } }
private void TraverseNodes(XmlNodeList nodes, FileProcessStatusEnum FileProcess) { foreach (XmlNode node in nodes) { // Do something with the node. if (FileProcess == FileProcessStatusEnum.AllStatus) { if (node.Name == "File") { CountNumber++; } } if (node.Name == "File" && node.Attributes["FileStatus"].Value == FileProcess.ToString()) { CountNumber++; } TraverseNodes(node.ChildNodes, FileProcess); } }