Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mguster/7029ab6f0bdbe1354cee2fae79dfb50a to your computer and use it in GitHub Desktop.
Save mguster/7029ab6f0bdbe1354cee2fae79dfb50a to your computer and use it in GitHub Desktop.
/// <summary>
/// Gets executed by the ExportButton OnClick event
/// </summary>
protected void ExportButtonClick(object sender, EventArgs e)
{
try
{
List<Item> childItemList = GetChildrenFromTargetItem(TargetTextBox.Text, SummaryLiteral);
if (!childItemList.Any())
{
SummaryLiteral.Text = "No Child items for specified target item";
return;
}
ExportButton.Enabled = false;
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=UserExport-" + DateTime.Now.ToString("dd_MM_yyyy_HH_mm_ss") + ".csv");
Response.Charset = "";
Response.ContentType = "application/text";
Response.Output.Write(GetCsv(childItemList));
ExportButton.Enabled = true;
SummaryLiteral.Text = "Successfully finished export.";
Response.Flush();
Response.End();
}
catch (System.Threading.ThreadAbortException)
{
// exception can be ignored
}
catch (Exception ex)
{
Response.Write(ex.ToString());
SummaryLiteral.Text = "Error occured during export.";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment