string path = "D:\\SYNC\\Reports.xls";
FileInfo filexist = new FileInfo(path);
if (filexist.Exists)
{
File.Delete(path);
}
else if (!Directory.Exists("D:\\SYNC\\"))
{
Directory.CreateDirectory("D:\\SYNC\\");
}
using (StringWriter sw = new StringWriter())
{
using (HtmlTextWriter hw = new HtmlTextWriter(sw))
{
bid.MainCompCode = Session["Comp"].ToString();
bid.MainLocCode = Session["Loc"].ToString();
bid.UserName = Session["Userid"].ToString();
bid.Procedure = "gridfetch";
bid.ScreenName = Request.QueryString["proc"].ToString();
bid.Date4Filter = DateTime.Today.AddDays(-1).Date;
adddatapage = Request.QueryString["page"].ToString();
bid.CompCode = "";
DataTable dt = new DataTable();
dt = cn.fillgrid(bid);
GridView gr = new GridView();
gr.DataSource = dt;
gr.DataBind();
for (int i = 0; i < gr.HeaderRow.Cells.Count; i++)
{
if (i != 0 && i != 1)
{
gr.HeaderRow.Style.Add("background-color", "#FFFFFF");
gr.HeaderRow.Cells[i].Style.Add("background-color", "#507CD1");
}
}
int j = 1;
foreach (GridViewRow gvrow in gr.Rows)
{
if (j <= gr.Rows.Count)
{
if (j % 2 != 0)
{
for (int k = 0; k < gvrow.Cells.Count; k++)
{
if (k != 0 && k != 1)
{
gvrow.Cells[k].Style.Add("background-color", "#EFF3FB");
}
}
}
}
j++;
}
FileStream fs = new FileStream("D:\\SYNC\\Reports.xls",FileMode.OpenOrCreate,FileAccess.ReadWrite);
StreamWriter writer = new StreamWriter(fs);
gvCountry.RenderControl(hw);
writer.WriteLine(sw.ToString());
writer.Close();
}
}
msg("File downloaded at D:\\SYNC\\Reports.xls");
bindgrid();
My application running on server ip, when i am downloading data, it is checking server local folder to download,instead of client machine folder for download....