This is a migrated thread and some comments may be shown as answers.

Prevent PDF/HTML Export From Opening in Browser

3 Answers 21 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Steven
Top achievements
Rank 1
Steven asked on 25 Jan 2019, 05:46 PM
Is there a way to force a file download instead of opening PDF/HTML in the browser with the built in MasterTableView.ExportToXXXX() function?

3 Answers, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 28 Jan 2019, 01:48 PM
Hello Steven,

Setting the OpenInNewWindow property under ExportSettings to true will add the content-disposition: attachment HTTP header to the response with the exported content: https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/functionality/exporting/overview#properties-and-events. It is important to note that it is up to the browser and end user OS to determine what to do with the file and the content-disposition header is only a suggestion the web app can make, it cannot influence the client OS.


Regards,
Marin Bratanov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Steven
Top achievements
Rank 1
answered on 29 Jan 2019, 10:11 PM

It appears none of my ExportSettings are working.  They did when I first started this project but now stopped and nothing I can do will bring them back.  For example, the .FileName does not take and the Excel keeps coming out as html..  This code is pretty straight forward but nothing takes on the ExportSettings. 

<telerik:RadGrid runat="server" ID="RadGridAccessList" CellSpacing="0" GridLines="None"
    CssClass="GridHeightSetAuto" AllowSorting="False" AutoGenerateColumns="False" PageSize="50" AllowPaging="false" AllowFilteringByColumn="false" AllowMultiRowSelection="false" HeaderStyle-Font-Bold="true" OnItemDataBound="RadGridAccessList_ItemDataBound" OnGridExporting="RadGridAccessList_GridExporting">
 
protected void RadGridAccessList_GridExporting(object sender, GridExportingArgs e)
{
    loadAccessList(this.PropertyID);
    ConfigureExport();
 
    switch (e.ExportType)
    {
        case ExportType.Excel:
            RadGridAccessList.ExportSettings.Excel.Format = GridExcelExportFormat.Biff;
            RadGridAccessList.ExportSettings.Excel.Format = GridExcelExportFormat.ExcelML;
            RadGridAccessList.MasterTableView.ExportToExcel();
            break;
 
        case ExportType.Csv:
            RadGridAccessList.ExportSettings.Csv.EncloseDataWithQuotes = true;
            RadGridAccessList.MasterTableView.ExportToCSV();
            break;
    }
}
 
private void ConfigureExport()
{
    RadGridAccessList.ExportSettings.ExportOnlyData = true;
    RadGridAccessList.ExportSettings.IgnorePaging = true;
    RadGridAccessList.ExportSettings.OpenInNewWindow = true;
    RadGridAccessList.ExportSettings.FileName = "AccessList";
}
0
Marin Bratanov
Telerik team
answered on 30 Jan 2019, 11:49 AM
Hello Steven,

I advise that you compare the problematic grid with the one in our demos where the approach of changing the export format works as expected: https://demos.telerik.com/aspnet-ajax/grid/examples/functionality/exporting/excel-export/defaultcs.aspx.

If this does not help you resolve this, I advise that you open a support ticket and send us a runnable page that demonstrates the problem so we can debug it.


Regards,
Marin Bratanov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Steven
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Steven
Top achievements
Rank 1
Share this question
or