Hi friends,
i am trying to download excel with the formt xlsx but its downloading only .xls format.. Attached code for reference.. please Help.
public string GetDemandforecastingExcelTemplate(string period, string key) // New
{
string _html = "";
try
{
_sqlParameter = null;
_sqlCommand = "[SGGD_SEK].[USP_AG_GET_DEMAND_FORECASTING]";
_sqlParameter = new SqlParameter[] {
new SqlParameter("@keyWord","Template"),
new SqlParameter("@User_Code", Session["UserCode"].ToString()),
new SqlParameter("@XML",""),
new SqlParameter("@Period",period),
new SqlParameter("@WithData",key),
new SqlParameter("@ReportType",""),
new SqlParameter("@FILTERKEYWORD",""),
new SqlParameter("@FilterValue",""),
new SqlParameter("@isSuccess","0")
};
_sqlHelper = new SQLHelper();
_businessHelper = new BusinessHelper();
_dataTable = _sqlHelper.GetDataTable(_sqlCommand, _sqlParameter);
string attachment = "attachment; filename=city.xlsx";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/vnd.ms-excel";
string tab = "";
foreach (DataColumn dc in _dataTable.Columns)
{
Response.Write(tab + dc.ColumnName);
tab = "\t";
}
Response.Write("\n");
int i;
foreach (DataRow dr in _dataTable.Rows)
{
tab = "";
for (i = 0; i < _dataTable.Columns.Count; i++)
{
Response.Write(tab + dr[i].ToString());
tab = "\t";
}
Response.Write("\n");
}
Response.End();
}
catch (Exception ex)
{
if (ex.Message == "Object reference not set to an instance of an object.")
{
_html = "SESSION~";
}
}
return _html;
}