使用遞歸獲取網站下的所有同類型文件 - 中國WEB開發者網絡 (http://www.webasp.net) -- 技術教程 (http://www.webasp.net/article/) --- 使用遞歸獲取網站下的所有同類型文件 (http://www.webasp.net/article/13/12473.htm) |
| -- 作者:未知 -- 發佈日期: 2004-08-21 |
| 紅色字體就是啦,如有不明白的話,請與我聯繫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> /// 得到站點內的所有Aspx文件,並存入Xml文件中 /// </summary> public class GetAllFiles { public GetAllFiles() { // // TODO: 在此處添加構造函數邏輯 // } /// <summary> /// 更新Xml文件的某個支點 /// </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> /// 寫入Xml文件 /// </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> /// 返回所有的Aspx文件 /// </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); } } } } } } |
| webasp.net |