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
10 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Francis SusaimichaelPosted Apr 3, 2016, 9:17 AM
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;
}
}
MR alaaPosted Apr 4, 2016, 4:47 AM
Francis SusaimichaelPosted Apr 4, 2016, 3:13 AM
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 alaaPosted Apr 3, 2016, 4:38 PM
Francis SusaimichaelPosted Apr 3, 2016, 12:22 PM
MR alaaPosted Apr 3, 2016, 11:49 AM
MR alaaPosted Apr 3, 2016, 7:16 AM
";
Francis SusaimichaelPosted Apr 3, 2016, 7:01 AM
MR alaaPosted Apr 3, 2016, 6:53 AM
Francis SusaimichaelPosted Apr 3, 2016, 6:48 AM
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
}