HI All
I have a project as to load data in Gridview from Client, then let Client to save a CSV file (filename.csv) on the client side as wherever they want not on the web server. I have a code as below is to save direct to "root of server", If anyone has this experience please help me. Thank you very much for your time and help;
Here is code
//How to change this code line to save on Client wherever they want Please
I have a project as to load data in Gridview from Client, then let Client to save a CSV file (filename.csv) on the client side as wherever they want not on the web server. I have a code as below is to save direct to "root of server", If anyone has this experience please help me. Thank you very much for your time and help;
Here is code
//How to change this code line to save on Client wherever they want Please
Code:
StreamWriter sw = new StreamWriter(Server.MapPath("~/GridDataMINH.txt"), false);
// First we will write the headers.
int columns = GridView1.Columns.Count;
int rows = GridView1.Rows.Count;
int y;
int count = 0;
for (int x = 0; x < columns; x++)
{
count = 0;
for (y = 0; y < rows; y++)
{
if (GridView1.Rows[y].Cells[x].Text == " ")
{
count++;
GridView1.Rows[y].Cells[x].Text = GridView1.Rows[y].Cells[x].Text.Replace(" ", " ");
}
else
{
y = rows;
}
if (count == rows)
{
GridView1.Columns[x].Visible = false;
}
}
}
int iColCount = GridView1.Columns.Count;
for (int i = 0; i < iColCount; i++)
{
sw.Write(GridView1.Columns[i]);
if (i < iColCount - 1)
{
sw.Write(",");
}
}
sw.Write(sw.NewLine);
// Now write all the rows.
int myrows = GridView1.Rows.Count;
// foreach (DataRow dr in GridView2.Rows)
for (int ty = 0; ty < myrows; ty++)
{
for (int i = 0; i < iColCount; i++)
{
if (!Convert.IsDBNull(GridView1.Rows[ty].Cells[i].Text))
{
sw.Write(GridView1.Rows[ty].Cells[i].Text);
}
if (i < iColCount - 1)
{
sw.Write(",");
}
}
sw.Write(sw.NewLine);
}
sw.Close();
GridView1.Visible = true;
// // Response.End();
Comment