hi every body
i have folder in my website where i can loop in it and get all files ordered i need to add anew column to an exist data set this my code
string sourceDir = Server.MapPath("~/folder1/folder2/");
string[] fileEntries = Directory.GetFiles(sourceDir).OrderBy(filename => filename).ToArray();
foreach (string fileName in fileEntries)
{
string x = "
";
";
}
this data set already have data i need to add anew colum to the same dataset with the image path from previous code
if (ds.Tables.Count > 0)
{
// do something
}
how it can be done

Francis SusaimichaelRank #466 · 5.4K reputationPosted Apr 3, 2016, 5:17 AM EDT
DataColumn column;
DataRow row;
// Create first column and add to the DataTable.
column = new DataColumn();
column.DataType = System.Type.GetType("System.Int32");
column.ColumnName = "ChildID";
column.Caption = "ID";
// Add the column to the DataColumnCollection.
table.Columns.Add(column);
for (int i = 0; i <= 4; i++)
{
row = table.NewRow();
row["childID"] = i;
table.Rows.Add(row);
}
DataSet ds = new DataSet();
ds.Tables.Add(table);
string[] filename = { "a.gif", "b.gif", "c.gif", "d.gif", "e.gif" };
if(ds.Tables.Count >0 )
{
//grab the datatable from dataset
DataTable dt=ds.Tables[0];
// Add your extra column
dt.Columns.Add("YourColumnName", typeof(System.String));
// to do your rest of the operation
int cnt = 0;
foreach(string str in filename)
{
dt.Rows[cnt]["YourColumnName"] = str;
cnt = cnt + 1;
}
}
Francis SusaimichaelRank #466 · 5.4K reputationPosted Apr 3, 2016, 2:48 AM EDT
if(ds.Tables.Count >0 )
{
//grap the datatable from dataset
DataTable dt=ds.Tables[0];
// Add your extra column
dt.Columns.Add("YourColumnName", typeof(System.String));
// to do your rest of the operation
}
MR alaaRank #2,683 · 519 reputationPosted Apr 3, 2016, 2:53 AM EDT
Francis SusaimichaelRank #466 · 5.4K reputationPosted Apr 3, 2016, 3:01 AM EDT
MR alaaRank #2,683 · 519 reputationPosted Apr 3, 2016, 3:16 AM EDT
";
MR alaaRank #2,683 · 519 reputationPosted Apr 3, 2016, 7:49 AM EDT
Francis SusaimichaelRank #466 · 5.4K reputationPosted Apr 3, 2016, 8:22 AM EDT
MR alaaRank #2,683 · 519 reputationPosted Apr 3, 2016, 12:38 PM EDT
Francis SusaimichaelRank #466 · 5.4K reputationPosted Apr 3, 2016, 11:13 PM EDT
Substitute the below code wherever you want:
string str = "c://websites/app/images/folder1/";
string[] res = str.Split('/');
string yourdesiredpath = string.Concat("/", res[5], "/");
MR alaaRank #2,683 · 519 reputationPosted Apr 4, 2016, 12:47 AM EDT