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. Image for the cookie policy date
Starting in 2019, the Reporting control is no longer included in Essential Studio. If you're experiencing issues with the Syncfusion Reporting Platform, Report Viewer, Report Designer, or Report Writer, we recommend migrating to Bold Reports, our dedicated reporting platform.

Bold Reports offers a comprehensive suite of tools and features for all your reporting needs, and we will help you make a smooth transition from the discontinued control. Our support team at https://support.boldreports.com/ is here to assist you with any questions or difficulties you may encounter during the migration process.

We thank you for choosing Syncfusion and appreciate your understanding.

ReportWriter issue while editing the reportdefinition at runtime

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:





3 Replies

YD Yuvaraj Devarajan Syncfusion Team August 30, 2017 10:54 AM UTC

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. 



YU Yusiro August 30, 2017 06:28 PM UTC

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.



YD Yuvaraj Devarajan Syncfusion Team August 31, 2017 04:58 AM UTC

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.

Loader.
Live Chat Icon For mobile
Up arrow icon