Hello
I need to provide an export to excel function for my customer but it seems that downloading a file could not work when using a map menu link....
any advice?
thanks.
jm
Hello
I need to provide an export to excel function for my customer but it seems that downloading a file could not work when using a map menu link....
any advice?
thanks.
jm
public void ExportToSpreadsheet(DataTable table, string name)
{
HttpContext context = HttpContext.Current;
context.Response.Clear();
context.Response.ContentType = @"text/csv";
context.Response.AppendHeader("Content-Disposition", "attachment; filename=" + name + ".csv");
foreach (DataColumn column in table.Columns)
{
context.Response.Write(column.ColumnName + ";");
}
context.Response.Write(Environment.NewLine);
foreach (DataRow row in table.Rows)
{
for (int i = 0; i < table.Columns.Count; i++)
{
context.Response.Write(row[i].ToString().Replace(";", string.Empty) + ";");
}
context.Response.Write(Environment.NewLine);
}
context.Response.End();
}
Map control try to intercept the stream that is sent from the asp page…
Hi Jean-Marie,
I would first try setting up your code to write out your Excel file to the server file system perhaps using a GUID for the filename and then setup some JavaScript to open that file in a new window. Let me know how this works for you.
Hi,
I would like to do this from the map context menu…
any idea?
Hi Jean-Marie,
Have you tried ryan’s idea?
For context menu you can find a AddAContextMenu sample in our HowDoISample.
Regards,
Don
Hi Jean-marie,
Your code works, the only thing you need to do is put map control out of UpdatePanel.
If you call some API like HttpContext.Current.Response.Write in post back of Updatepanel, the exception will be thrown.
Regards,
Don