8 Answers, 1 is accepted
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.
All the best,
Peter
the Telerik team
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.
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
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()"
}
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
I'm also attaching a new sample application demonstrating how it should work with the newest version.
Best Regards,
Silviya
Progress Telerik
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;
}
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/.