快精灵印艺坊 您身边的文印专家
广州名片 深圳名片 会员卡 贵宾卡 印刷 设计教程
产品展示 在线订购 会员中心 产品模板 设计指南 在线编辑
 首页 名片设计   CorelDRAW   Illustrator   AuotoCAD   Painter   其他软件   Photoshop   Fireworks   Flash  

 » 彩色名片
 » PVC卡
 » 彩色磁性卡
 » 彩页/画册
 » 个性印务
 » 彩色不干胶
 » 明信片
   » 明信片
   » 彩色书签
   » 门挂
 » 其他产品与服务
   » 创业锦囊
   » 办公用品
     » 信封、信纸
     » 便签纸、斜面纸砖
     » 无碳复印纸
   » 海报
   » 大篇幅印刷
     » KT板
     » 海报
     » 横幅

使用递归获取网站下的所有同类型文件

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

}
}
}

}

}
}
返回类别: 教程
上一教程: ASP中COOKIE读写的实现方式
下一教程: 正则表达式简介(9-10)

您可以阅读与"使用递归获取网站下的所有同类型文件"相关的教程:
· 读取目录下的所有文件(源码)
· 读取目录下的所有文件(源码)
· 列出指定目录下的所有文件和目录
· 获取网站的RSS聚合到自己的网页
· XMLHTTP异步获取网站数据的例子
    微笑服务 优质保证 索取样品