Telerik Radgrid export file name
Asked Answered
K

3

6

Does any one know how to provide file name to the exported file in Telerik RadGrid, Exported file could be of any format pdf, excel or word

Kidd answered 13/6, 2012 at 9:40 Comment(0)
R
5

Source: Grid / MS Excel/MS Word/CSV

Use RadGrid.ExportSettings.FileName property, a string specifying the name (without the extension) of the file that will be created. The file extension is automatically added based on the method that is used Try setting the FileName in the ItemCommand event as shown below.

From: When to set RadGrid.ExportSettings.FileName

protected void Radgrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.ExportToPdfCommandName)
    {
        Radgrid1.ExportSettings.FileName = "yourfilename";
    }
    if (e.CommandName == RadGrid.ExportToExcelCommandName)
    {
        Radgrid1.ExportSettings.FileName = "yourfilename";
    }
    if (e.CommandName == RadGrid.ExportToWordCommandName)
    {
        Radgrid1.ExportSettings.FileName = "yourfilename";
    }
}

Reference:
Export RadGrid content to Excel/Word/CSV/PDF with Ajax enabled

Repro answered 13/6, 2012 at 9:58 Comment(2)
Has anybody gotten the filename property to work correctly? It is getting ignoredby the RadGrid export when I attempt to set it.Rhpositive
yes me too... tried several events but it's always ignoredPlan
D
1

You can set the filename as well as other options for exporting, on the ExportSettings property of the grid (not the MasterTableView). So for example:

myGrid.ExportSettings.FileName = "file";
myGrid.ExportSettings.Excel.Extension = "xls";
myGrid.MasterTableView.ExportToExcel();
Deprecatory answered 13/6, 2012 at 9:47 Comment(2)
According to the docs you should leave out the extension - "a string specifying the name (without the extension)" demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/…Kappel
@Kevin Main I forgot that was the case indeed. Although I do think that the export function will ignore the extension if you leave it in. But I'm not able to test it now, so I'll edit it. Thanks!Deprecatory
A
0
     try
     {
        object districtid = Session["DistID"];

        RadGrid tempGrid = rgDupEmpoyees;
        string fileName = "LEA_" + districtid .ToString() + "_PossibleNoShowTonySopranoEmployees_" + DateTime.Now.ToString("dd_MMM_yyyy");
        tempGrid.ExportSettings.FileName = fileName;
        tempGrid.ClientSettings.Scrolling.UseStaticHeaders = false;
        tempGrid.MasterTableView.ExportToPdf();
     }
     catch (Exception ex)
     {
        this.LogException(ex);
        DisplayPageMessage(ex.GetBaseException().Message, PageMessageType.Error);
        //e.Cancel = true;
     }
     finally
     {
        this.LogMethodExit();
     }
Apophthegm answered 27/1, 2023 at 22:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.