yogi
yogi

Reputation: 19591

Telerik Radgrid export file name

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

Upvotes: 6

Views: 11973

Answers (3)

ARLibertarian
ARLibertarian

Reputation: 167

     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();
     }

Upvotes: 0

Niranjan Singh
Niranjan Singh

Reputation: 18290

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

Upvotes: 5

pyrocumulus
pyrocumulus

Reputation: 9290

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();

Upvotes: 1

Related Questions