日期:2014-05-18 浏览次数:20619 次
using System.IO; DirectoryInfo df1 = new DirectoryInfo(Server.MapPath("."));//当前目录 FileInfo[] f1 = df1.GetFiles("*.xml",SearchOption.TopDirectoryOnly);//只搜索当前目录 for (int i = 0; i < f1.Length; i++) { if (f1[i].Extension.ToLower() == ".xml")//检查扩展名 { Response.Write(f1[i].Name + "<br>"); } }
------解决方案--------------------
//public class MyCacheDependency : System.Web.Caching.CacheDependency
//{
// private FileSystemWatcher watcher;
// public MyCacheDependency(string filePath)
// {
// watcher = new FileSystemWatcher
// (HttpContext.Current.Server.MapPath(filePath));
// watcher.EnableRaisingEvents = true;
// watcher.Created += new FileSystemEventHandler
// (watcher_Created);
// watcher.Deleted += new FileSystemEventHandler
// (watcher_Created);
// watcher.Changed += new FileSystemEventHandler
// (watcher_Created);
// }
// void watcher_Created(object sender, FileSystemEventArgs e)
// {
// if (Path.GetExtension(e.Name) == ".htm" || Path.GetExtension(e.Name) == ".html")
// {
// //System.Threading.Thread.Sleep(1000);
// base.NotifyDependencyChanged(sender, e);
// }
// }
//}
这个是以前做文件依赖缓存用得,当添加新文件得时候也能清除缓存,不知道对你有帮助没!