protected void Button1_Click(object sender, EventArgs e)
{
try
{
ds = clpl.FetchSnapdealupdateFeed(1, 5);
if (ds != null)
{
if (ds.Tables.Count > 0)
{
if (ds.Tables[0].Rows.Count > 0)
{
// var dataTable = GetData();
StringBuilder builder = new StringBuilder();
List<string> columnNames = new List<string>();
List<string> rowss = new List<string>();
foreach (DataColumn column in ds.Tables[0].Columns)
{
columnNames.Add(column.ColumnName);
}
builder.Append(string.Join(",", columnNames.ToArray())).Append("\n");
foreach (DataRow row in ds.Tables[0].Rows)
{
List<string> currentRow = new List<string>();
foreach (DataColumn column in ds.Tables[0].Columns)
{
object item = row[column];
currentRow.Add(item.ToString());
}
rowss.Add(string.Join(",", currentRow.ToArray()));
}
builder.Append(string.Join("\n", rowss.ToArray()));
string Year = DateTime.Now.Year.ToString();
string Month = DateTime.Now.Month.ToString();
string Day = DateTime.Now.Day.ToString();
if (Day.Length == 1) { Day = '0' + Day; }
if (Month.Length == 1) { Month = '0' + Month; }
string spathTime = Day + "-" + Month + "-" + Year;
using (StreamWriter sw = new StreamWriter(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath.ToString() + "snapdealfile/" + spathTime + "_snap.csv", true))
{
sw.WriteLine(builder.ToString());
sw.Flush();
sw.Close();
Response.Write("Create Succssefuly");
}
}
}
}
}
}
{
try
{
ds = clpl.FetchSnapdealupdateFeed(1, 5);
if (ds != null)
{
if (ds.Tables.Count > 0)
{
if (ds.Tables[0].Rows.Count > 0)
{
// var dataTable = GetData();
StringBuilder builder = new StringBuilder();
List<string> columnNames = new List<string>();
List<string> rowss = new List<string>();
foreach (DataColumn column in ds.Tables[0].Columns)
{
columnNames.Add(column.ColumnName);
}
builder.Append(string.Join(",", columnNames.ToArray())).Append("\n");
foreach (DataRow row in ds.Tables[0].Rows)
{
List<string> currentRow = new List<string>();
foreach (DataColumn column in ds.Tables[0].Columns)
{
object item = row[column];
currentRow.Add(item.ToString());
}
rowss.Add(string.Join(",", currentRow.ToArray()));
}
builder.Append(string.Join("\n", rowss.ToArray()));
string Year = DateTime.Now.Year.ToString();
string Month = DateTime.Now.Month.ToString();
string Day = DateTime.Now.Day.ToString();
if (Day.Length == 1) { Day = '0' + Day; }
if (Month.Length == 1) { Month = '0' + Month; }
string spathTime = Day + "-" + Month + "-" + Year;
using (StreamWriter sw = new StreamWriter(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath.ToString() + "snapdealfile/" + spathTime + "_snap.csv", true))
{
sw.WriteLine(builder.ToString());
sw.Flush();
sw.Close();
Response.Write("Create Succssefuly");
}
}
}
}
}
}
No comments:
Post a Comment