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

Export to XML

8 Answers 680 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
ethan
Top achievements
Rank 1
ethan asked on 29 Jan 2011, 01:10 AM
Hi! Is there a sample that adds Export to XML from the report export menu? Thanks.

8 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 01 Feb 2011, 05:48 PM
Hello ethan,

Currently there is no out of the box solution for this inquiry. Although there is almost no information on the matter, it is possible to create your own rendering extensions and plug it into the reporting engine. 

Attached you may find a sample WinDemo project that contains a sample implementation of custom rendering extension that renders the report in XML as by your request.

As far as the implementation is concerned the most interesting parts are:

  • The XmlRenderingExtension is the actual rendering extension that does the work on transforming the processing report into a XML. Please note how the createStreamCallback is used for the extension to ask the reporting engine for a storage for the generated document;
  • Once you have the XmlTextWriter, the only thing left is to traverse the processing report items' and create the appropriate XML nodes;
  • The app.config contains the registration of our custom rendering extension so the reporting engine can use it. For more information please see Configuring Telerik Reporting.
As you can see the implementation is quite straightforward and although there is no documentation or other information on the matter I would suggest you to give it a try.

All the best,
Peter
the Telerik team
Get started with Telerik Reporting with numerous videos and detailed documentation.
0
Jayson
Top achievements
Rank 1
answered on 30 Jun 2015, 12:31 PM

Hi, I integrate the sample above (XML-RenderingExtensioWinDemo.zip) into telerik sample project - CSharp.Html5Demo.

Using xml export on html 5 report viewer gave me this error:

{"message":"An error has occurred.","exceptionMessage":"Buffer cannot be null.\r\nParameter name: buffer","exceptionType":"System.ArgumentNullException","stackTrace":" at System.IO.MemoryStream..ctor(Byte[] buffer, Boolean writable)\r\n at System.IO.MemoryStream..ctor(Byte[] buffer)\r\n at Telerik.Reporting.Services.WebApi.ReportsControllerBase.GetDocument(String clientID, String instanceID, String documentID)\r\n at lambda_method(Closure , Object , Object[] )\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass13.<GetExecutor>b__c(Object instance, Object[] methodParameters)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.<>c__DisplayClass5.<ExecuteAsync>b__4()\r\n at System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func`1 func, CancellationToken cancellationToken)"}

I only added the extension class and the web.config entry for the extension.

 (I tested the extension on web form report viewer. It works fine.)

Please help.

0
Nasko
Telerik team
answered on 30 Jun 2015, 03:40 PM
Hello Jayson,

The sample solution needs a check which allows the rendering extension to indicate that there is no additional content to be added to the stream. You can modify the XmlRenderingExtension class from the sample solution as shown in the following code snippet:
public class XmlRenderingExtension : Telerik.Reporting.Processing.IRenderingExtension
{
    public bool Render(Telerik.Reporting.Processing.Report report
        , System.Collections.Hashtable renderingContext
        , System.Collections.Hashtable deviceInfo
        , Telerik.Reporting.Processing.CreateStream createStreamCallback
        , Telerik.Reporting.Processing.EvaluateHeaderFooterExpressions evalHeaderFooterCallback)
    {
        var stream = createStreamCallback("report/xml", "xml", Encoding.UTF8, "application/xml");
 
        using (var xmlWriter = new XmlTextWriter(stream, Encoding.UTF8))
        {
            new XmlReportWriter(xmlWriter).Write(report);
        }
 
        var renderingStream = stream as IRenderStream;
 
        if(null != renderingStream)
        {
            renderingStream.Finish();
        }
 
        return true;
    }
 
    void Telerik.Reporting.IExtension.Initialize(System.Collections.Hashtable deviceInfo)
    {
    }
 
    public void Dispose()
    {
    }
}

Please find attached a sample solution with the HTML5 Report Viewer implementation and the custom XML export option.

Regards,
Nasko
Telerik
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 Feedback Portal and vote to affect the priority of the items
0
Graham
Top achievements
Rank 1
answered on 15 Jul 2019, 10:09 AM

Hi, I still get this error even though I am calling .Finish() on the IRenderExtension - call stack below:

 

message: "An error has occurred.",
exceptionMessage: "Buffer cannot be null. Parameter name: buffer",
exceptionType: "System.ArgumentNullException",
stackTrace: " at System.IO.MemoryStream..ctor(Byte[] buffer, Boolean writable) at Telerik.Reporting.Services.WebApi.ReportsControllerBase.GetDocument(String clientID, String instanceID, String documentID) at lambda_method(Closure , Object , Object[] ) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__0.MoveNext()"
}

0
Silviya
Telerik team
answered on 18 Jul 2019, 08:23 AM

Hi Graham,

I'm afraid that we couldn't reproduce this error. We tested with the latest version of Telerik Reporting, e.g. 13.1.19.618. May I ask you to share your current installed version and also, if it's possible, to open a new support ticket and send us the problematic project for further investigation?

Best Regards, Silviya
Progress Telerik

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 Feedback Portal and vote to affect the priority of the items
0
Silviya
Telerik team
answered on 18 Jul 2019, 10:28 AM
Hi Graham,

I'm also attaching a new sample application demonstrating how it should work with the newest version.

Best Regards,
Silviya
Progress Telerik
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 Feedback Portal and vote to affect the priority of the items
0
Thorsten
Top achievements
Rank 1
answered on 11 Sep 2020, 08:08 AM

Hello,

i have tried your solution for an own csv export and it works so far.

For an export i don't need the report and its reportitems (textboxes and so on), rather i need the rawdata which i get through my objectdatasource. How can i access the rawdata in my csvExtension?

Here my Example:

I fill some data into my objectdatasource:
[DataObjectMethod(DataObjectMethodType.Select)]
        public IList<ReceiptJournalModel> GetResult(DateTime? pdFromDate, DateTime? pdToDate, string psDateMode, object[] psDeviceFilter, object[] psUserFilter, string pReceiptNumber, byte pReceiptJournalGroupBy)
        {
            //get some data
            IList<ReceiptJournalModel> lOResult = mOHelper.GetResult(pdFromDate, pdToDate, psDateMode, psDeviceFilter, psUserFilter, pReceiptNumber, pReceiptJournalGroupBy);
            return lOResult;
        }

How can i use this list in my extension?
bool IRenderingExtension.Render(Telerik.Reporting.Processing.Report pReport
            , Hashtable pRenderingContext
            , Hashtable pDeviceInfo
            , CreateStream pCreateStreamCallback
            , EvaluateHeaderFooterExpressions pEvalHeaderFooterCallback)
        {
            try
            {
                if (pRenderingContext["CountOnly"]?.ToString() == "True")
                    return true;

                var lEncoding = fGetEncodingFromString(pDeviceInfo["Encoding"].ToString());

                Stream lStream = pCreateStreamCallback("report/RawData", "csv", Encoding.UTF8, "application/csv");

                using (var lStreamWriter = new StreamWriter(lStream, lEncoding))
                {
                    //if Datasource would be is typeof Ilist<objectmodel> then it works :-)
                    Type lType = pReport.DataSource?.GetType().GetGenericArguments().Single();
                    var lProps = lType?.GetProperties(BindingFlags.Public | BindingFlags.Instance).OrderBy(p => p.Name);
                    if (lProps != null)
                    {
                        lStreamWriter.WriteLine(string.Join("; ", lProps?.Select(p => p.Name)));

                        foreach (var item in (IEnumerable)pReport.DataSource)
                            lStreamWriter.WriteLine(string.Join("; ", lProps.Select(p => p.GetValue(item, null))));
                    }
                }
                var lRenderingStream = lStream as IRenderStream;
                lRenderingStream?.Finish();

            }
            catch (Exception ex)
            {
                return false;
            }
            
            return true;
        }

0
Eric R | Senior Technical Support Engineer
Telerik team
answered on 15 Sep 2020, 02:01 PM

Hi Thorsten,

This thread is related to Exporting to XML and I see that you are inquiring about exporting to CSV. To keep things better organized, I have created a ticket specific to your question which can be accessed through your Telerik Account

Please use this ticket for any future communication related to your question. Thank you.

Regards,


Eric R | Senior Technical Support Engineer
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
General Discussions
Asked by
ethan
Top achievements
Rank 1
Answers by
Peter
Telerik team
Jayson
Top achievements
Rank 1
Nasko
Telerik team
Graham
Top achievements
Rank 1
Silviya
Telerik team
Thorsten
Top achievements
Rank 1
Eric R | Senior Technical Support Engineer
Telerik team
Share this question
or