Use recursion to get all the files of the same type under the Web

Source: Internet
Author: User
Tags foreach cdata httpcontext tostring
Recursive red font is, if you do not understand, please contact me qq:20028205





using System;


using System.Text;


using System.IO;


using System.Xml;


using System.Xml.XPath;


using System.Web;


using System.Collections;








namespace GST.Common.Xml


{


///<summary>


///gets all the ASPX files in the site and stores them in an XML file


///</summary>


public class Getallfiles


{


public getallfiles ()


{


//


//TODO: Add constructor logic here


//


}








///<summary>


///Update a fulcrum of an XML file


///</summary>


///<param name= "Files" ></param>


///<param name= "Desc" ></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]. innertext = Desc;


}





Doc. Save (HttpContext.Current.Server.MapPath (FILESRC));





}





///<summary>


///write to XML file


///</summary>


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));

















}


<summary>


///returns all ASPX files


///</summary>


///<returns>string array</returns>


public void Getallaspxfile (string webpath,ref ArrayList al)


{








string[] aspxfiles = 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 al);





}

















}





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);





}


}


}














}





}


}

















Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.