使用递归获取网站下的所有同类型文件
2004-08-19 18:51
519 查看
红色字体就是啦,如有不明白的话,请与我联系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);
}
}
}
}
}
}
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);
}
}
}
}
}
}
相关文章推荐
- ATL实现Connection Point的一种简单的方法
- Java测试规范(引用)
- oracle中的分页
- Java面试题目
- delphi中的时间操作技术(2)
- DirectX.Capture
- 解析IP地址为主机域名
- 将某一主机域名解析为IP地址
- 有关TrueDBGrid的问题向各位大虾请教
- 力争最简单把*、&说清楚
- 一个画图类,类似ms_chart的线图,适用于科学仿真数据分析(一)
- 怎样为任何控件和区域添加提示信息:用自己封装的CTip类
- 使用 .NET 框架将现有代码作为 Web 服务提供
- 使用C#开发COM+组件
- 纯编码实现数据库的建立或压缩
- 从数据库中动态选取下拉列表的方法
- 用ASP备份数据库
- Netscaler数据索引String Map与Pattern Set的区别
- 2014年软考数据库系统工程师知识点讲解(1)