We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

ReportWriter issue while editing the reportdefinition at runtime

Thread ID:

Created:

Updated:

Platform:

Replies:

132379 Aug 29,2017 10:35 AM Aug 31,2017 12:58 AM ASP.NET MVC 3
loading
Tags: ReportViewer
Yusiro
Asked On August 29, 2017 10:35 AM

Hi,

I'm trying to use ReportWriter object to save my rdl file to pdf.
As I created DataSource object in my report using ReportDesigner and i didn't store connectionproperties username and password there,
I need to modify the reportdefinition using xmlserializer at runtime. I have followed the sample found in other threads but encountered some issues here.
I managed to convert my report definition to stream and tried to load the stream using ReportWriter but i got "root element is missing" error message.
After having no luck solving it, i save the report definition to new rdl file and use the ReportDesigner to open it, i got
"The element 'Report' in namespace http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition has invalid child element" error message
and couldn't open the file.

The red arrow in the image is the line where i hit error.
Please assist, Thanks.
My code is as below:





Yuvaraj Devarajan [Syncfusion]
Replied On August 30, 2017 06:54 AM

Hi Yusiro, 

Thanks for contacting Syncfusion support. 

We can set the datasource credential detail (UserName, Password) in ReportWriter Action method dynamically instead of editing the ReportDefinition XML file and we have SetDataSourceCredentials method to pass the credential detail of the report as shown in below code example, 

        public ActionResult Index(string writerFormat) 
        { 
            try 
            { 
                string fileName = null; 
                WriterFormat format; 
                HttpContext httpContext = System.Web.HttpContext.Current; 
                ReportWriter reportWriter = new ReportWriter(); 
                reportWriter.ReportPath = Server.MapPath("~/App_Data/GroupingAgg.rdl"); 
                reportWriter.ReportProcessingMode = ProcessingMode.Remote; 
 
                DataSourceCredentials _credential = new DataSourceCredentials(); 
                _credential.Name = "AdventureWorks"; //Datasource name 
                _credential.UserId = "ssrs1"; 
                _credential.Password = "RDLReport1"; 
 
                IList<DataSourceCredentials> _credentials = new List<DataSourceCredentials>(); 
                _credentials.Add(_credential); 
                reportWriter.SetDataSourceCredentials(_credentials); 
               
                if (writerFormat == "PDF") 
                { 
                    fileName = "GroupingAgg.pdf"; 
                    format = WriterFormat.PDF; 
                } 
                else if (writerFormat == "Word") 
                { 
                    fileName = "GroupingAgg.doc"; 
                    format = WriterFormat.Word; 
                } 
                else if (writerFormat == "Html") 
                { 
                    fileName = "GroupingAgg.Html"; 
                    format = WriterFormat.HTML; 
                } 
                else if (writerFormat == "PPT") 
                { 
                    fileName = "GroupingAgg.ppt"; 
                    format = WriterFormat.PPT; 
                } 
                else 
                { 
                    fileName = "GroupingAgg.xls"; 
                    format = WriterFormat.Excel; 
                } 
                reportWriter.Save(fileName, format, httpContext.Response); 
            } 
            catch 
            { 
            } 
            return View(); 
        } 
    } 
  
We have prepared a ReportWriter sample and it can be downloaded from below location, 

You can obtain the complete ASP.NET MVC ReportWriter sample in below build installed location, 
%userprofile%\AppData\Local\Syncfusion\EssentialStudio\version\ MVC\Samples\web 

Regards, 
Yuvaraj D. 


Yusiro
Replied On August 30, 2017 02:28 PM

Hi,

I have followed all the sample but my generated PDF file i still unable to get the info. All the fields remain empty. Please let me know what have i missed here.

Thanks very much.


Yuvaraj Devarajan [Syncfusion]
Replied On August 31, 2017 12:58 AM

Hi Yusiro, 
 
On further analysis of the shared code example, the mentioned issue might be occurred when you have specified the processing mode as “local” to load the RDL file in your application. So please specify the processing mode as “Remote” to load the RDL report in your application to avoid the mentioned problem as shown in below code example, 
 
        public ActionResult Index(string writerFormat) 
        { 
            try 
            { 
                string fileName = null; 
                WriterFormat format; 
                HttpContext httpContext = System.Web.HttpContext.Current; 
                ReportWriter reportWriter = new ReportWriter(); 
                reportWriter.ReportPath = Server.MapPath("~/App_Data/GroupingAgg.rdl"); 
                reportWriter.ReportProcessingMode = ProcessingMode.Remote; 
 
                DataSourceCredentials _credential = new DataSourceCredentials(); 
                _credential.Name = "AdventureWorks"; //Datasource name 
                _credential.UserId = "ssrs1"; 
                _credential.Password = "RDLReport1"; 
 
                IList<DataSourceCredentials> _credentials = new List<DataSourceCredentials>(); 
                _credentials.Add(_credential); 
                reportWriter.SetDataSourceCredentials(_credentials); 
               
                if (writerFormat == "PDF") 
                { 
                    fileName = "GroupingAgg.pdf"; 
                    format = WriterFormat.PDF; 
                } 
                else if (writerFormat == "Word") 
                { 
                    fileName = "GroupingAgg.doc"; 
                    format = WriterFormat.Word; 
                } 
                else if (writerFormat == "Html") 
                { 
                    fileName = "GroupingAgg.Html"; 
                    format = WriterFormat.HTML; 
                } 
                else if (writerFormat == "PPT") 
                { 
                    fileName = "GroupingAgg.ppt"; 
                    format = WriterFormat.PPT; 
                } 
                else 
                { 
                    fileName = "GroupingAgg.xls"; 
                    format = WriterFormat.Excel; 
                } 
                reportWriter.Save(fileName, format, httpContext.Response); 
            } 
            catch 
            { 
            } 
            return View(); 
        } 
 
Regards, 
Yuvaraj D.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;