Use recursion to get all the same type of file under the site

xiaoxiao2021-03-06  109

The red font is, if you don't understand, please contact me QQ: 20028205

Using system; using system.x; using system.xml.xpath; using system.web; using system.collections;

Namespace gst.common.xml {///

// Nate all ASPX files in the site, and deposit /////////////////////////// // TODO: Add constructor logic //} here

///

/// Update a fulcrum of the XML file /// /// /// < / param> public void updatexmlfile (string files, string desc, string filesrc) {xmldocument doc = new xmldocument (); doc.load (httpcontext.current.server.mappath (filesrc));

XMLNode node = doc.selectsinglenode ("/ aspxfiles / file [text () = /" " files " / "]");

IF (Node! = null) {node.attributes [0] .INNNERTEXT = DESC;

Doc.save (httpcontext.current.server.mappath (filesrc));

} ///

/// Write XML file /// public void writexmlfile (string filesrc, arraylist al) {xmldocument doc = new xmldocument (); doc.load (httpContext.current.server. Mappath (filesrc); xmlelement element = doc.documenTelement; Bool Update = false;

Foreach (Object Obj IN Al) {xmlnode node = doc.selectsinglenode ("/ aspxfiles / file [text () = /" " Obj.toString () " / "]"); if (node ​​== null) { XmlElement ElementChild = doc.CreateElement ( "File"); ElementChild.InnerText = obj.ToString (); XmlCDataSection cdata = doc.CreateCDataSection (obj.ToString ()); XmlAttribute attribute = doc.CreateAttribute ( "Desc"); attribute. Value = cdata.Value; ElementChild.Attributes.Append (attribute); Element.AppendChild (ElementChild); Update = true;}} if (Update) doc.Save (HttpContext.Current.Server.MapPath (fileSrc));

} ///

/// Return all ASPX files /// /// string array public void getallaspxfile (String WebPath, Ref arraylist al) {string [] aspfiles = Directory.GetDirectories (WebPath); if (AspxFiles.Length> 0) {foreach (string AspFile in AspxFiles) {foreach (string InnerFile in Directory.GetFiles (AspFile)) {if (Path.GetExtension (InnerFile) .ToLower () == ". aspx") {

String filename = path.GetFileName (Innerfile); al.add (filename);}} getallaspxfile (aspfile, ref allow);}

} Else {

String [] FILES = Directory.getFiles (WebPath); FOREACH (String Aspfile IN Files) {IF (path.getextension (aspfile) .tolower () == "ASPX") {

String filename = path.GetFileName (aspfile); al.add (filename);}}}}

}

转载请注明原文地址:https://www.9cbs.com/read-125338.html

New Post(0)