Example #1
0
        //private static int _minutes;

        //protected void SetCatch()
        //{
        //    string minutes = ConfigurationManager.AppSettings["CacheSlidingTime"];
        //    if (string.IsNullOrEmpty(minutes) || !int.TryParse(minutes, out _minutes))
        //    {
        //        _minutes = 10; // 默认为10分钟。
        //    }
        //}
        public List <FilesInfo> FindFile(string dir) //参数为指定的目录
        {
            //在指定目录及子目录下查找文件,在listBox1中列出子目录及文件
            DirectoryInfo    Dir      = new DirectoryInfo(dir);
            List <FilesInfo> fileList = new List <FilesInfo>();

            try
            {
                //foreach (DirectoryInfo d in Dir.GetDirectories())     //查找子目录
                //{
                //    FindFile(Dir + d.ToString() + "\\");
                //    lbResult.Items.Add(Dir.Name);       //listBox1中填加目录名
                //}
                foreach (FileInfo f in Dir.GetFiles("*.*"))             //查找文件
                {
                    FilesInfo fileInfo = new FilesInfo();
                    fileInfo.FileName       = f.Name;
                    fileInfo.FileSize       = f.Length / 1024;
                    fileInfo.CreateDate     = f.LastWriteTime;
                    fileInfo.UrlQueryString = Server.UrlEncode(f.Name);
                    fileList.Add(fileInfo);
                }
            }
            catch (Exception e)
            {
            }
            return(fileList);
        }
Example #2
0
        //参数为指定的目录
        //private static int _minutes;
        //protected void SetCatch()
        //{
        //    string minutes = ConfigurationManager.AppSettings["CacheSlidingTime"];
        //    if (string.IsNullOrEmpty(minutes) || !int.TryParse(minutes, out _minutes))
        //    {
        //        _minutes = 10; // 默认为10分钟。
        //    }
        //}
        public List<FilesInfo> FindFile(string dir)
        {
            //在指定目录及子目录下查找文件,在listBox1中列出子目录及文件
            DirectoryInfo Dir = new DirectoryInfo(dir);
            List<FilesInfo> fileList = new List<FilesInfo>();
            try
            {
                //foreach (DirectoryInfo d in Dir.GetDirectories())     //查找子目录
                //{
                //    FindFile(Dir + d.ToString() + "\\");
                //    lbResult.Items.Add(Dir.Name);       //listBox1中填加目录名
                //}
                foreach (FileInfo f in Dir.GetFiles("*.*"))             //查找文件
                {
                    FilesInfo fileInfo = new FilesInfo();
                    fileInfo.FileName = f.Name;
                    fileInfo.FileSize = f.Length/1024;
                    fileInfo.CreateDate = f.LastWriteTime;
                    fileInfo.UrlQueryString =Server.UrlEncode(f.Name);
                    fileList.Add(fileInfo);
                }
            }
            catch (Exception e)
            {

            }
            return fileList;
        }