S
Simple Simon
Hi,
I'm filling DataTable1 with the filenames from within a directory, and
filling another DataTable2 with filenames from a SQL Db table. I'd
like to compare the two, and delete the files from the directory that
do not occur in DataTable2
StringBuilder sb = new StringBuilder();
string strDirectory = "C:\\Temp\\";
// DataTable1 ************************************************
DataTable dt = new DataTable("DiFiles");
dt.Columns.Add(new DataColumn("filename",
Type.GetType("System.String")));
System.IO.DirectoryInfo di = new DirectoryInfo(strDirectory);
// loop thru the files in the directory
foreach (FileInfo fi in di.GetFiles())
{
DataRow dr;
dr = dt.NewRow();
dr["filename"] = fi.Name;
dt.Rows.Add(dr);
sb.Append(fi.Name);
sb.Append("<br>");
}
Response.Write(sb.ToString());
//DataTable2 ***********************************************
string strCon, strSQL;
DataSet ds = new DataSet();
strCon = "***** ************* ************** ******";
strSQL = "SELECT filename FROM Files";
SqlDataAdapter da = new SqlDataAdapter(strSQL, strCon);
da.Fill(ds, "DbFiles");
// need help here on
TIA,
~Gordon
I'm filling DataTable1 with the filenames from within a directory, and
filling another DataTable2 with filenames from a SQL Db table. I'd
like to compare the two, and delete the files from the directory that
do not occur in DataTable2
StringBuilder sb = new StringBuilder();
string strDirectory = "C:\\Temp\\";
// DataTable1 ************************************************
DataTable dt = new DataTable("DiFiles");
dt.Columns.Add(new DataColumn("filename",
Type.GetType("System.String")));
System.IO.DirectoryInfo di = new DirectoryInfo(strDirectory);
// loop thru the files in the directory
foreach (FileInfo fi in di.GetFiles())
{
DataRow dr;
dr = dt.NewRow();
dr["filename"] = fi.Name;
dt.Rows.Add(dr);
sb.Append(fi.Name);
sb.Append("<br>");
}
Response.Write(sb.ToString());
//DataTable2 ***********************************************
string strCon, strSQL;
DataSet ds = new DataSet();
strCon = "***** ************* ************** ******";
strSQL = "SELECT filename FROM Files";
SqlDataAdapter da = new SqlDataAdapter(strSQL, strCon);
da.Fill(ds, "DbFiles");
// need help here on
TIA,
~Gordon