Below is my code to download the data in excel but the problem is while downloading it is not showing that the file is getting downloaded moreover i am giving the path in this way as given below to download the file in downloads folder but i should not use this because it works in local host but it will not work when hosted in server.how can i download into downloads folder with showing the downloading file at bottom
protected void btnExportExcel_Click(object sender, EventArgs e)
{
string pathDownload = @"~\Downloads\" Data.xls";
ExportToExcel(dsExcel, pathDownload);
lblMessage.Text = "Downloaded Successfully";
}
private void ExportToExcel(DataSet table, string filePath)
{
int tablecount = table.Tables.Count;
StreamWriter sw = new StreamWriter(filePath, false);
sw.Write(@"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">");
sw.Write("<font style='font-size:10.0pt; font-family:Calibri;'>");
sw.Write("<BR><BR><BR>");
sw.Write("<Table border='1' bgColor='#ffffff' borderColor='#000000' cellSpacing='0' cellPadding='0' style='font-size:10.0pt; font-family:Calibri; background:'#1E90FF'> <TR>");
sw.Write("</Table>");
//sw.Write("<BR><BR><BR><BR>");
//sw.Write("\n");
//sw.Write(string.Format("Line1{0}Line2{0}", Environment.NewLine));
sw.Write("</font>");
}
sw.Close();
}
this is the path that i am getting ~\Downloads\DATA.xls
and i am getting this exception Could not find a part of the path 'C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\11.0\~\Downloads\DATA.xls'. StreamWriter sw = new StreamWriter(filePath, false);