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

Cannot set FileName of exported data

2 Answers 82 Views
Grid
This is a migrated thread and some comments may be shown as answers.
kith
Top achievements
Rank 1
kith asked on 03 Jun 2011, 03:07 AM
Hello Guys,

I am trying to set the filename of my exported excel file but I am still getting the default filename "RadGridExport". Am I missing something?


<telerik:RadGrid ID="myRadGrid" CssClass="AutoShrink" runat="server" GridLines="Both" OnItemCommand="myRadGrid_ItemCommand">           
    <HeaderStyle Font-Bold="True" HorizontalAlign="Center" Wrap="True" />
</telerik:RadGrid>


Public Sub btnExport_Click(ByVal sender As Object, ByVal args As EventArgs)
        myRadGrid.MasterTableView.ExportToExcel()
End Sub

Protected Sub myRadGrid_ItemCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles myRadGrid.ItemCommand
    If e.CommandName = Telerik.Web.UI.RadGrid.ExportToExcelCommandName Then
        myRadGrid.ExportSettings.ExportOnlyData = True
        myRadGrid.ExportSettings.IgnorePaging = True
        myRadGrid.ExportSettings.OpenInNewWindow = True
        myRadGrid.ExportSettings.FileName = "myFilename"
    End If
End Sub

Any help is appreciated.

Thanks!

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 03 Jun 2011, 05:11 AM
Hello Kith,

Try the following code snippet to set file name for exported excel.

VB:
Protected Sub RadGrid1_ItemCommand(sender As Object, e As GridCommandEventArgs)
    If e.CommandName = "ExportToExcel" Then
        RadGrid1.ExportSettings.FileName = "Customers"
        RadGrid1.MasterTableView.ExportToExcel()
        RadGrid1.Rebind()
    End If
End Sub

Another suggestion is you can directly set file name for exported excel in aspx as shown below. Hope this helps you.

aspx:
<ExportSettings ExportOnlyData="true" Excel-Format="ExcelML" FileName="Customers" >
</
ExportSettings>


Thanks,
Princy.
0
kith
Top achievements
Rank 1
answered on 03 Jun 2011, 06:14 AM
Hey Princy,

Thanks for the reply :) I tried your first suggestion but still it didn't work. I want the name dynamic so I didn't try the second one.
Anyway, I move the code "ExportSettings.FileName" to my ButtonClick routine and it worked!

Thanks for the help again :)
Tags
Grid
Asked by
kith
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
kith
Top achievements
Rank 1
Share this question
or