Forum Discussion

Aure's avatar
Aure
Occasional Contributor
10 years ago
Solved

Export data from RadTreeListView (Telerik ThirdParty)

Hi Everyone,

I need to export the results contained in a RadTreeListView object.
There is a lot of data inside and i can't afford to process cells and rows one by one (in terms of testing time)

 

I see that RadTreeListView object give access to the method:

Export(System.IO.Stream stream, Telerik.Windows.Controls.GridViewExportOptions options)

 

The only issue I get is to provide the seconde parameter define in this doc.

 

I have the Telerik DLL library if needed.

Is there a way to provide the GridViewExportOptions to the method?

 

Thanks!

  • Try using the dotNET object obtained directly from the tree list object. Maybe the global dotNET object uses a different .NET version than that used in the app, and that causes conflicts.

    Also note that Export needs a Stream object, not a StreamWriter. A FileStream should work.

     

    var dotNET2 = RootApp.Grid.ContentControl.ContentPresenter.RadTreeListView.ClrAppDomain.dotNET;
    
    // Use dotNET2 to create parameters for the Export method call // Initialize GridViewExportOptions var options = dotNET2.Telerik_Windows_Controls.GridViewExportOptions.zctor(); options.Encoding = dotNET2.System_Text.Encoding.Unicode; options.ShowColumnHeaders = true; options.ShowColumnFooters = true; // Initialize the FileStream var fileStream = dotNET2.System_IO.File.Create(path); RootApp.Grid.ContentControl.ContentPresenter.RadTreeListView.Export(fileStream, options); fileStream.Close();

4 Replies

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    You can create a GridViewExportOptions object like this:

    // JScript

    // Get the dotNET object from the app,
    // so that it's compatible with the app's .NET version var dotNET2 = Sys.Process("YourApp").AppDomain("YourApp.exe").dotNET; var options = dotNET2.Telerik_Windows_Controls.GridViewExportOptions.zctor(); options.Format = dotNET2.Telerik_Windows_Controls.ExportFormat.Xlsx; options.Encoding = dotNET2.System_Text.Encoding.Unicode; options.ShowColumnHeaders = true;

     

    • Aure's avatar
      Aure
      Occasional Contributor

      Thousands thanks for you answer HKosova!
      I did not know about this trick, it will help me a lot in the future.

      Unfortunately i am getting exception while calling the Export method.
      Here is the exception:

      Invalid procedure call or argument
      Error location:
      Unit: "TestProject2\TestProject2\Script\Unit1"
      Line: 28 Column: 3. (Where i call the Export method)
       
       
      Here is my code:
        //Initialize GridViewExportOptions  
      var dotNET2=Aliases.MachiningCloudApp.AppDomain("MachiningCloudApp.exe").dotNET;
        var options = dotNET2.Telerik_Windows_Controls.GridViewExportOptions.zctor();
        options.Format = dotNET2.Telerik_Windows_Controls.ExportFormat.Csv;
        options.Encoding = dotNET2.System_Text.Encoding.Unicode;
        options.ShowColumnHeaders = true;
        options.ShowColumnFooters= true;
        
        //Initialize the StreamWriter
        var sw =dotNET.System_IO.StreamWriter.zctor_5(path);
        sw.AutoFlush=true;
      
        //Call Export method (RootApp represents the parent aliases). RootApp.Grid.ContentControl.ContentPresenter.RadTreeListView.Export(sw,options);
        
        //Close the stream
        sw.Close();

       

      I am not really sure if i missed somthing or if the issue is on the app side.

      Thanks for you help!

      • HKosova's avatar
        HKosova
        SmartBear Alumni (Retired)

        Try using the dotNET object obtained directly from the tree list object. Maybe the global dotNET object uses a different .NET version than that used in the app, and that causes conflicts.

        Also note that Export needs a Stream object, not a StreamWriter. A FileStream should work.

         

        var dotNET2 = RootApp.Grid.ContentControl.ContentPresenter.RadTreeListView.ClrAppDomain.dotNET;
        
        // Use dotNET2 to create parameters for the Export method call // Initialize GridViewExportOptions var options = dotNET2.Telerik_Windows_Controls.GridViewExportOptions.zctor(); options.Encoding = dotNET2.System_Text.Encoding.Unicode; options.ShowColumnHeaders = true; options.ShowColumnFooters = true; // Initialize the FileStream var fileStream = dotNET2.System_IO.File.Create(path); RootApp.Grid.ContentControl.ContentPresenter.RadTreeListView.Export(fileStream, options); fileStream.Close();