Hi,
I want using creating Excel File using OpenXML and C# ASP.Net
My code below work and the Excel File is created correctly.
Now I need adding on the Excel file name the value get of the dropdownlist from my aspx page.
Compiler Error CS0120
An object reference is required for the nonstatic field, method, or property 'member'
When I try to setting the value of dropdownlist on public static void method
Any suggestion?
Thanks in advance for any help
public static void ExportDataSetToExcel(DataSet ds)
{
string AppLocation = @"D:\Public\ExcelFiles\";
string guid = Guid.NewGuid().ToString().ToUpper().Replace("-", "_");
HttpContext.Current.Response.Cookies["guid"].Value = guid.ToString();
HttpContext.Current.Response.Cookies["guid"].Expires = DateTime.Now.AddMinutes(3);
string filepath = AppLocation +
ddlut.SelectedValue.ToString() + "_" +
DateTime.Now.ToString("ddMMyyyyHHmm") + "_" +
HttpContext.Current.Response.Cookies["guid"].Value + ".xlsx";
using (XLWorkbook wb = new XLWorkbook())
{
for (int i = 0; i < ds.Tables.Count; i++)
{
wb.Worksheets.Add(ds.Tables[i], ds.Tables[i].TableName);
}
wb.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
wb.Style.Font.Bold = true;
wb.SaveAs(filepath);
wb.Dispose();
}
Thread.Sleep(3000);
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.ContentType = "application/force-download";
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment; filename=" +
ddlut.SelectedValue.ToString() + "_" +
DateTime.Now.ToString("ddMMyyyyHHmm") + "_" +
HttpContext.Current.Response.Cookies["guid"].Value + ".xlsx");
HttpContext.Current.Response.TransmitFile(@"D:\Public\ExcelFiles\" +
ddlut.SelectedValue.ToString() + "_" +
DateTime.Now.ToString("ddMMyyyyHHmm") + "_" +
HttpContext.Current.Response.Cookies["guid"].Value + ".xlsx");
HttpCookie cookie = new HttpCookie("ExcelDownloadFlag")
{
Value = "Flag",
Expires = DateTime.Now.AddDays(1)
};
HttpContext.Current.Response.AppendCookie(cookie);
HttpContext.Current.Response.End();
}