Replies
Hi Divya,
Thank you I try to implement like that in future. For now I did following:
protected void btnExport_Click(object sender, EventArgs e)
{
try
{
if (wdgModifyPositions.Rows.Count >= 1)
{
//disable paging before exporting
this.wdgModifyPositions.Behaviors.Paging.Enabled= false;
this.wdgModifyPositions.DataBind();
//export data
this.exporter.Export(this.wdgModifyPositions);
lblError.Visible = false;
AlertPic.Visible = false;
//enable paging
this.wdgModifyPositions.Behaviors.Paging.Enabled = true;
this.wdgModifyPositions.DataBind();}
I wanted to know how can I append date to download file name. Currently I am using downloadName
<ig:WebExcelExporter ID="exporter" runat="server" DownloadName="ModifyPositions" >
</ig:WebExcelExporter>
I would like file name be like ModifyPositioons20161205.xls
I tried following but it does not work:
protected void btnExport_Click(object sender, EventArgs e)
{
try
{
if (wdgModifyPositions.Rows.Count >= 1)
{
//disable paging before exporting
this.wdgModifyPositions.Behaviors.Paging.Enabled= false;
this.wdgModifyPositions.DataBind();
//export data
this.exporter.Export(this.wdgModifyPositions);
lblError.Visible = false;
AlertPic.Visible = false;
//enable paging
this.wdgModifyPositions.Behaviors.Paging.Enabled = true;
this.wdgModifyPositions.DataBind();
string FileName = HttpUtility.UrlEncode("ModifyPositions" + DateTime.Now.ToString());
Response.Clear();
Response.AddHeader("content-disposition", "attachment; filename=" +FileName);
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter WriteItem = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlText = new HtmlTextWriter(WriteItem);
wdgModifyPositions.RenderControl(htmlText);
Response.Write(WriteItem.ToString());
Response.End();
this.exporter.DownloadName = FileName;
else
{
lblError.Text = "Please Load Data into the Data Grid";
lblError.Visible = true;
AlertPic.Visible = true;
}
}
catch (Exception ex)
{
ErrorHandle.ExceptionHelper(ex);
}
}