We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Render reports programmatically


I am using Aspose.Words for Reporting Services to export my report to a txtfile. I was able to integrate with Microsoft Report Viewer in Local Mode successfully, but now I would like to perform the export programmatically.

After searching the documentation/forums, I came across a post that relates to my question: Render as word through Code . Can you please extend on this post by providing a more complete explanation and example on how to render reports programmatically? I am using Visual Studio 2005 to create the report.



Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for your interest in Aspose.Words for Reporting Services. Here is a nice article that describes how to render reports programmatically.


I created sample code based on this article that shows how to render the report in DOC format.

// Create a new proxy to the web service

rs2005.ReportingService2005 rs = new rs2005.ReportingService2005();

rsExecService.ReportExecutionService rsExec = new rsExecService.ReportExecutionService();

// Authenticate to the Web service using Windows credentials

rs.Credentials = System.Net.CredentialCache.DefaultCredentials;

rsExec.Credentials = System.Net.CredentialCache.DefaultCredentials;

// Assign the URL of the Web service

rs.Url = "http://localhost/ReportServer/ReportService2005.asmx";

rsExec.Url = "http://localhost/ReportServer/ReportExecution2005.asmx";

// Prepare Render arguments

string historyID = null;

string deviceInfo = null;

string format = "AWDOC";

Byte[] results;

string encoding = String.Empty;

string mimeType = String.Empty;

string extension = String.Empty;

rsExecService.Warning[] warnings = null;

string[] streamIDs = null;

// Default Path;

string fileName = @"c:\Temp\samplereport.doc";

// Define variables needed for GetParameters() method

// Get the report name

string _reportName = @"/AdventureWorks Sample Reports/Sales Order Detail";

string _historyID = null;

bool _forRendering = false;

rs2005.ParameterValue[] _values = null;

rs2005.DataSourceCredentials[] _credentials = null;

rs2005.ReportParameter[] _parameters = null;



// Get if any parameters needed.

_parameters = rs.GetReportParameters(_reportName, _historyID,

_forRendering, _values, _credentials);

// Load the selected report.

rsExecService.ExecutionInfo ei =

rsExec.LoadReport(_reportName, historyID);

// Prepare report parameter.

// Set the parameters for the report needed.

rsExecService.ParameterValue[] parameters =

new rsExecService.ParameterValue[1];

// Place to include the parameter.

if (_parameters.Length > 0)


parameters[0] = new rsExecService.ParameterValue();

parameters[0].Label = "SalesOrderNumber";

parameters[0].Name = "SalesOrderNumber";

parameters[0].Value = "SO50750";


rsExec.SetExecutionParameters(parameters, "en-us");

results = rsExec.Render(format, deviceInfo,

out extension, out encoding,

out mimeType, out warnings, out streamIDs);

// Create a file stream and write the report to it

using (FileStream stream = File.OpenWrite(fileName))


stream.Write(results, 0, results.Length);



catch (Exception ex)




Hope this could be useful for you.

Best regards.

Thank you for your help. I have been able to use the webservices mentioned above to export my report.

I am currently evaluating your product, to see what other things I can do with it. I was wondering if I can also programmatically convert the .rdlc file to a text file from a winforms application, without the need to connect to the internet. I want to see the same functionality that I get when I click on the export button in the ReportViewer control (after adding your extensions), but I want my code to control when this export occurs as opposed to waiting for the user to click on a button.

Can this be done using Apose.Words for Reporting Services, and if so, can you give an example?

Thanks again,



Yes, you surely can do that. The clue is the use of the ReportViewer.LocalReport.Render() method. After you have integrated Aspose.Words for Reporting Services with ReportViewer as described here


(you told you had succeeded in that), consider the use of the ReportViewer.LocalReport.Render method to get a stream containing the resulting document:


You should use the format name as the first argument, i.e. "AWDOC" for DOC or "AWTXT" for TXT.

Please let me know if it works, I'll be eager to help if you experience any issues.



I have added the code sample you requested to the product's documentation. Please visit the following page: