C# 遍历文件夹加载到DataSet里面

  1.     /// <summary>
  2.     /// 根据文件夹路径得到文件路径下所有的文件
  3.     /// </summary>
  4.     /// <param name="pathtext"></param>
  5.     //public void ListFiles(string pathtext)
  6.     //{
  7.     //    try
  8.     //    {
  9.             
  10.     //        if (pathtext == null ||pathtext.Equals(""))
  11.     //        {
  12.     //            Response.Write("路径不能为空错误");
  13.     //        }
  14.     //        else
  15.     //        {
  16.     //            //得到文件名,目录
  17.     //            string[] filename = Directory.GetFiles(Server.MapPath(pathtext));
  18.     //            //初始化文件计数器
  19.     //            int a = 0;
  20.     //            //初始化文件大小
  21.     //            long j = 0;
  22.     //            //遍历文件夹
  23.     //            foreach (string file in filename)
  24.     //            {
  25.     //                 FileInfo f = new FileInfo(file);
  26.     //                //得到文件的创建时间
  27.     //                DataRow dr1 = Photo_LibraryTable.NewRow();
  28.     //                //Photo_ID    Photo_Path Photo_Name State       Star_LibraryID
  29.     //                dr1["Photo_ID"] = "0";//ID编号
  30.     //                dr1["Photo_Path"] = "/Star/"+modelStar_Library.Pinyin+"/";//存储的地址
  31.     //                dr1["Photo_Name"] = f.Name;//文件名称
  32.     //                dr1["State"] = "1";//表示已审核
  33.     //                dr1["Star_LibraryID"] = modelStar_Library.Stage_Name;//明星艺名
  34.     //                foreach(DataRow dr in Photo_Libraryds.Rows)
  35.     //                {
  36.                       
  37.     //                    DateTime CreationTime = File.GetCreationTime(file);//文件创建时间
  38.     //                   // string strfilename = file.Substring(file.LastIndexOf("//") + 1);//取得文件名
  39.     //                    //string strfileend = file.Substring(file.LastIndexOf(".") + 1);//取得文件类型
  40.     //                    //得到文件的大小
  41.                        
  42.     //                    string strFile = dr["Photo_Name"].ToString();//得到数据库存储的没有进行审核的相片名称
  43.     //                    if (strFile==f.Name) //如果名称相同 则设置成没有审核
  44.     //                    {
  45.     //                        dr1["State"] = "0";//表示未审核 
  46.     //                    }
  47.     //                   // long len = f.Length;//单个文件大小
  48.     //                   // j = j + len;//总文件大小
  49.     //                  //  a++;//文件个数
  50.     //                }
  51.     //                Photo_LibraryTable.Rows.Add(dr1);
  52.     //                //Response.Write(f.Name);
  53.     //                //得到符合条件的文件,某个时间段之前的文件
  54.     //                //file文件地址
  55.     //               // Response.Write(file+"file<br/>");
  56.                    
  57.                    
  58.     //                //Response.Write(len.ToString()+"文件大小<br/>");
  59.                    
  60.     //            }
  61.     //            this.gvPhoto_LibraryList.DataSource = Photo_LibraryTable;
  62.     //            this.gvPhoto_LibraryList.DataBind();
  63.     //            //关闭窗口
  64.     //            //Response.Write (a.ToString()+"文件个数<br/>");//输出个数
  65.     //           // int i = a;
  66.     //            //Response.Write(j.ToString());
  67.     //           // long x = j /1024;
  68.     //            //Response.Write(x.ToString() + "KB 文件大小<br/>");//得到大小
  69.     //            //Response.Write("搜索完毕!系统提示<br/>");
  70.     //        }
  71.     //    }
  72.     //    catch
  73.     //    {
  74.     //       // Response.Write("请检查路径是否正确");
  75.     //        Common.MsgBox2("文件路径读取错误!", "StarManage.aspx");
  76.     //    }
  77.     //}
原文地址:https://www.cnblogs.com/dingdingmao/p/3146582.html