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

Export to pdf and save programmatically

20 Answers 1065 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Anto (DLL Version : 2008.3.1314.35)
Top achievements
Rank 2
Anto (DLL Version : 2008.3.1314.35) asked on 03 Apr 2009, 10:25 AM
Hi All

I have a radgrid and button (Export To pdf)

The radgrid contains the data

When I click the Export to pdf button

The datas are shown in the pdf

Before that a screen appears for open or save

if open i given it opens the pdf

If save is given then the path if asked, and then it is saved

IS THERE ANY OPTION TO AUTOMATICALLY SAVE THE PDF

-Anto

20 Answers, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 03 Apr 2009, 10:38 AM
Hello Anto,

The following blog post will surely be helpful:
How To: Export grid to PDF file and show the result using the window

Best regards,
Daniel
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Anto (DLL Version : 2008.3.1314.35)
Top achievements
Rank 2
answered on 03 Apr 2009, 10:55 AM
Hi Daniel

What do I need is

The pdf should not be shown

When Export to pdf is clicked

The file must be automatically saved in a location specified in coding.

Is there any option for this

-Anto
0
Accepted
Daniel
Telerik team
answered on 03 Apr 2009, 11:31 AM
Hello Anto,

Have a look at the following code-snippet:

<asp:Button ID="Button1" runat="server" Text="Save on server" />  
<telerik:RadGrid ID="RadGrid1" runat="server" Skin="Vista" Width="500px">  
  <ExportSettings ExportOnlyData="true" />  
</telerik:RadGrid>  

Public Partial Class _Default  
    Inherits System.Web.UI.Page  
    Private url As String, path As String = ""  
  
    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load  
        url = [String].Format("~/{0}.pdf", RadGrid1.ExportSettings.FileName)  
        path = Server.MapPath(url)  
    End Sub  
  
    Protected Sub RadGrid1_NeedDataSource(source As Object, e As GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource  
        Dim table As New DataTable()  
        table.Columns.Add("ID"GetType(Integer))  
        table.Columns.Add("Name"GetType(String))  
        table.Rows.Add(1, "Michael")  
        table.Rows.Add(2, "George")  
        RadGrid1.DataSource = table  
    End Sub  
  
    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click  
        RadGrid1.MasterTableView.ExportToPdf()  
    End Sub  
    Protected Sub RadGrid1_GridExporting(source As Object, e As GridExportingArgs) Handles RadGrid1.GridExporting  
        If File.Exists(path) Then  
            'DELETE THE FILE IF ALREADY EXISTS  
            File.Delete(path)  
        End If  
        Using fs As FileStream = File.Create(path)  
            Dim info As [Byte]() = System.Text.Encoding.[Default].GetBytes(e.ExportOutput)  
                'SAVE IT ON THE SERVER  
            fs.Write(info, 0, info.Length)  
        End Using  
        Response.Redirect("~/Default.aspx")  
    End Sub  
End Class  

Regards,
Daniel
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Anto (DLL Version : 2008.3.1314.35)
Top achievements
Rank 2
answered on 03 Apr 2009, 11:39 AM
Hi Daniel

I am C# guy. Please could u send it in C#

-Anto
0
Accepted
Daniel
Telerik team
answered on 03 Apr 2009, 12:20 PM
Hello Anto,

You can find the C# version of this code in the link, I provided in my first post.

Alternatively you can use our online converter:
Code Converter

Regards,
Daniel
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Anto (DLL Version : 2008.3.1314.35)
Top achievements
Rank 2
answered on 06 Apr 2009, 11:36 AM
Hi Daniel

Thank you

I have solved it

-Anto
0
Ashwin Deshpande
Top achievements
Rank 1
answered on 25 Mar 2010, 11:38 AM
The code also worked for me ,but i do not want the Code to redirect to another page.
If i Comment out the code Response.Redirect("~/Default.aspx") the excel file Opens in same window.

Please Suugest  as i want to fals an information to the user  after export to excel and not redirect.

Regards,
Ashwin
0
Ashwin Deshpande
Top achievements
Rank 1
answered on 25 Mar 2010, 11:38 AM
The code also worked for me ,but i do not want the Code to redirect to another page.
If i Comment out the code Response.Redirect("~/Default.aspx") the excel file Opens in same window.

Please Suugest  as i want to fals an information to the user  after export to excel and not redirect.

Regards,
Ashwin
0
Ashwin Deshpande
Top achievements
Rank 1
answered on 25 Mar 2010, 11:38 AM
The code also worked for me ,but i do not want the Code to redirect to another page.
If i Comment out the code Response.Redirect("~/Default.aspx") the excel file Opens in same window.

Please Suugest  as i want to fals an information to the user  after export to excel and not redirect.

Regards,
Ashwin
0
Daniel
Telerik team
answered on 29 Mar 2010, 07:13 PM
Hello Ashwin,

As you properly noticed, if you don't redirect the response, it will reach the client's browser and will result in open/save dialog. The other option is to call Response.End, but this will show an empty page, so I doubt it will do the trick for you.

Regards,
Daniel
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Asutosh
Top achievements
Rank 1
answered on 13 Jun 2014, 09:51 AM
hi daniel
i want to export radgrid in hierarchy
and i dont want to use onneeddatasource
i bind datasource to radgrid in buttonclick event

code:
 gridname.ExportSettings.FileName = "filename";
            gridname.ExportSettings.ExportOnlyData = true;
            gridname.ExportSettings.IgnorePaging = true;
            gridname.ExportSettings.OpenInNewWindow = true;
            gridname.MasterTableView.UseAllDataFields = true;
            gridname.ExportSettings.Excel.Format = Telerik.Web.UI.GridExcelExportFormat.ExcelML;
            gridname.MasterTableView.HierarchyDefaultExpanded = true;
            gridname.MasterTableView.DetailTables[0].HierarchyDefaultExpanded = true;
            gridname.MasterTableView.HierarchyLoadMode = GridChildLoadMode.Client;
            gridname.MasterTableView.DetailTables[0].HierarchyLoadMode = GridChildLoadMode.Client;
            gridname.MasterTableView.ExportToExcel();

when i dont use onneeddatasource for grid it give me object reference is not set error







0
Kostadin
Telerik team
answered on 18 Jun 2014, 06:54 AM
Hi Asutosh,

Note that we strongly recommend to use advanced data-binding through NeedDataSource event when perform complex operations such hierarchy and export. Even if you manage to export the grid I could not be sure whether the export output will display all the information of the grid and whether the correct format will be applied.

Regards,
Kostadin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Pankaj
Top achievements
Rank 1
Veteran
answered on 23 May 2016, 01:33 PM

Hello Telerik team,

                               I have one excel template file  and I want to copy some sheets of that file and convert to PDF file. I am using .Net 3.5 version. Please suggest me step by step way if its possible form telerik. or also suggest me if possible from any free tool. I don't  want to purchase any other tool as I am using telerik for long time.

 

waiting for your response.

 

Regards

Pankaj

                          

0
Kostadin
Telerik team
answered on 26 May 2016, 07:52 AM
Hi Pankaj,

Please examine the following live example which demonstrates how to convert a Excel document to PDF.

Regards,
Kostadin
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Pankaj
Top achievements
Rank 1
Veteran
answered on 31 May 2016, 03:30 PM

Hello,

          I am not getting below DLL for .net 3.5 version. Can you help me where I will get it.

Imports Telerik.Windows.Documents.Spreadsheet.FormatProviders
Imports Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx
Imports Telerik.Windows.Documents.Spreadsheet.FormatProviders.Pdf
Imports Telerik.Windows.Documents.Spreadsheet.FormatProviders.TextBased.Csv
Imports Telerik.Windows.Documents.Spreadsheet.FormatProviders.TextBased.Txt
Imports Telerik.Windows.Documents.Spreadsheet.Model

0
Kostadin
Telerik team
answered on 03 Jun 2016, 08:12 AM
Hi Pankaj,

I am afraid DPL is not supported for .NET 3.5. You can find more information in the following help article.

Regards,
Kostadin
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
ArtiCut
Top achievements
Rank 1
answered on 06 Nov 2016, 10:24 AM
The command  " Response.Redirect(Request.Url.ToString());" redirect to the page,
but the data at the radGrid is empty - the parameters at the page not saved. It's a problem...

How can I come back to the page, but the parameters and the data should remain?
or How  can I export to excel and prevent the following message to appear without redirect to the page?
0
Daniel
Telerik team
answered on 07 Nov 2016, 11:20 AM
Hello,

If you'd like to save a file on the server using the built-in export, then you should use that approach. Alternatively you can generate the output file on your own by traversing the control and building the corresponding structure in code-behind.

Regards,
Daniel
Telerik by Progress
Check out the new UI for ASP.NET Core, the most complete UI suite for ASP.NET Core development on the market, with 60+ tried-and-tested widgets, based on Kendo UI.
0
ArtiCut
Top achievements
Rank 1
answered on 08 Nov 2016, 05:51 AM

As I understand from you - this is a limitation of Telerik "Save exporting file" mechanism, should  It be fixed in next version?  (this is very important)

Besides,
I am looking for an event that happened AFTER the Xslx file exported (in order to display alert - the RadWindowManager  does not show alert if I write it in the GridExporting event).

I would like to show a message when the file exporting completed.

Can you assist please?

0
Daniel
Telerik team
answered on 08 Nov 2016, 09:01 AM
Hello,

Straight onto your questions.

As I understand from you - this is a limitation of Telerik "Save exporting file" mechanism, should  It be fixed in next version?  (this is very important)
I'm afraid this can't be fixed. The built-in export functionality is designed to stream the output to the response. There are multiple changes made during the ASP.NET lifecycle which are irreversible.

I am looking for an event that happened AFTER the Xslx file exported (in order to display alert - the RadWindowManager  does not show alert if I write it in the GridExporting event).
There is no such event. If you want to be notified when the file is ready then you may use a cookie as shown here.
Show loading panel when exporting RadGrid


I'd like to note that none of these are supported out of the box.

Regards,
Daniel
Telerik by Progress
Check out the new UI for ASP.NET Core, the most complete UI suite for ASP.NET Core development on the market, with 60+ tried-and-tested widgets, based on Kendo UI.
Tags
Grid
Asked by
Anto (DLL Version : 2008.3.1314.35)
Top achievements
Rank 2
Answers by
Daniel
Telerik team
Anto (DLL Version : 2008.3.1314.35)
Top achievements
Rank 2
Ashwin Deshpande
Top achievements
Rank 1
Asutosh
Top achievements
Rank 1
Kostadin
Telerik team
Pankaj
Top achievements
Rank 1
Veteran
ArtiCut
Top achievements
Rank 1
Share this question
or