Export to pdf and save programmatically

21 posts, 3 answers
  1. Anto (DLL Version : 2008.3.1314.35)
    Anto (DLL Version : 2008.3.1314.35) avatar
    212 posts
    Member since:
    Mar 2009

    Posted 03 Apr 2009 Link to this post

    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
  2. Answer
    Daniel
    Admin
    Daniel avatar
    4943 posts

    Posted 03 Apr 2009 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Anto (DLL Version : 2008.3.1314.35)
    Anto (DLL Version : 2008.3.1314.35) avatar
    212 posts
    Member since:
    Mar 2009

    Posted 03 Apr 2009 Link to this post

    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
  5. Answer
    Daniel
    Admin
    Daniel avatar
    4943 posts

    Posted 03 Apr 2009 Link to this post

    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.
  6. Anto (DLL Version : 2008.3.1314.35)
    Anto (DLL Version : 2008.3.1314.35) avatar
    212 posts
    Member since:
    Mar 2009

    Posted 03 Apr 2009 Link to this post

    Hi Daniel

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

    -Anto
  7. Answer
    Daniel
    Admin
    Daniel avatar
    4943 posts

    Posted 03 Apr 2009 Link to this post

    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.
  8. Anto (DLL Version : 2008.3.1314.35)
    Anto (DLL Version : 2008.3.1314.35) avatar
    212 posts
    Member since:
    Mar 2009

    Posted 06 Apr 2009 Link to this post

    Hi Daniel

    Thank you

    I have solved it

    -Anto
  9. Ashwin Deshpande
    Ashwin Deshpande avatar
    31 posts
    Member since:
    Aug 2009

    Posted 25 Mar 2010 Link to this post

    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
  10. Ashwin Deshpande
    Ashwin Deshpande avatar
    31 posts
    Member since:
    Aug 2009

    Posted 25 Mar 2010 Link to this post

    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
  11. Ashwin Deshpande
    Ashwin Deshpande avatar
    31 posts
    Member since:
    Aug 2009

    Posted 25 Mar 2010 Link to this post

    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
  12. Daniel
    Admin
    Daniel avatar
    4943 posts

    Posted 29 Mar 2010 Link to this post

    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.
  13. Asutosh
    Asutosh avatar
    130 posts
    Member since:
    Sep 2013

    Posted 13 Jun 2014 in reply to Daniel Link to this post

    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







  14. Kostadin
    Admin
    Kostadin avatar
    1708 posts

    Posted 18 Jun 2014 Link to this post

    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.

     
  15. Pankaj
    Pankaj avatar
    16 posts
    Member since:
    Mar 2015

    Posted 23 May in reply to Kostadin Link to this post

    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

                              

  16. Kostadin
    Admin
    Kostadin avatar
    1708 posts

    Posted 26 May Link to this post

    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.
  17. Pankaj
    Pankaj avatar
    16 posts
    Member since:
    Mar 2015

    Posted 31 May in reply to Kostadin Link to this post

    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

  18. Kostadin
    Admin
    Kostadin avatar
    1708 posts

    Posted 02 Jun Link to this post

    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.
  19. ArtiCut
    ArtiCut avatar
    5 posts
    Member since:
    Nov 2016

    Posted 06 Nov in reply to Daniel Link to this post

    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?
  20. Daniel
    Admin
    Daniel avatar
    4943 posts

    Posted 07 Nov Link to this post

    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.
  21. ArtiCut
    ArtiCut avatar
    5 posts
    Member since:
    Nov 2016

    Posted 07 Nov in reply to Daniel Link to this post

    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?

  22. Daniel
    Admin
    Daniel avatar
    4943 posts

    Posted 08 Nov Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017