0

I am working on a project.Where "rdlc reporting" is used for reporting.I have some report that have different size of columns.So What i want is that I want to give width in my report properties and my rdlc report will get width according to that width.Previously width size was given in report view model like below--

string deviceInfo =

                "<DeviceInfo>" +
                "  <OutputFormat>" + this.Format.ToString() + "</OutputFormat>" +
            "  <PageWidth>8.5in</PageWidth>" +
            "  <PageHeight>8in</PageHeight>" +
            "  <MarginTop>0.5in</MarginTop>" +
            "  <MarginLeft>0.25in</MarginLeft>" +
            "  <MarginRight>0.25in</MarginRight>" +
            "  <MarginBottom>0.5in</MarginBottom>" +
            "</DeviceInfo>";

You can see my full reportview model below---

public class ReportViewModel
    {
         public enum ReportFormat         { PDF=1,Word=2,Excel=3}
        public ReportViewModel()
          {
              //initation for the data set holder
               ReportDataSets = new List<ReportDataSet>();
               ReportParams = new List<ReportParameter>();
         }
         //Name of the report
          public string Name { get; set; }

         //Language of the report
          public string ReportLanguage { get; set; }

          //Reference to the RDLC file that contain the report definition
        public string FileName { get; set; }                   
            public string LeftMainTitle { get; set; }
            public string LeftSubTitle { get; set; }
            public string ReportTitle { get; set; }

            //the url for the logo, 
            public string ReportLogo { get; set; }

            //dataset holder
            public List<ReportDataSet> ReportDataSets { get; set; }
            public List<ReportParameter> ReportParams { get; set; }

            //report format needed
            public ReportFormat Format { get; set; }
            public bool ViewAsAttachment { get; set; }

             //an helper class to store the data for each report data set
            public class ReportDataSet
            {
                public string DatasetName { get; set; }
                public List<object> DataSetData { get; set; }
            }
            public class DataSet
            {
                public string DatasetName { get; set; }
                public List<object> DataSetData { get; set; }
            }
            public string ReporExportFileName { get {
                return string.Format("attachment; filename={0}.{1}", this.ReportTitle, ReporExportExtention);
            } }
            public string ReporExportExtention
            {
                get
                {
                    switch (this.Format)
                    {
                        case ReportViewModel.ReportFormat.Word: return  ".doc"; 
                        case ReportViewModel.ReportFormat.Excel: return ".xls"; 
                        default:
                            return ".pdf";
                    }
                }
            }

            public string LastmimeType
            {
                get
                {
                    return mimeType;
                }
            }
            private string mimeType;
            public byte[] RenderReport()
            {
                try
                {
                    //creating a new report and setting its path
                    LocalReport localReport = new LocalReport();
                    localReport.ReportPath = this.FileName;

                    //adding the reort datasets with there names
                    foreach (var dataset in this.ReportDataSets)
                    {
                        ReportDataSource reportDataSource = new ReportDataSource(dataset.DatasetName, dataset.DataSetData);
                        localReport.DataSources.Add(reportDataSource);
                    }
                    //enabeling external images
                    localReport.EnableExternalImages = true;

                    foreach (var item in this.ReportParams)
                    {
                        localReport.SetParameters(item);
                    }

                    //seting the partameters for the report
                    //localReport.SetParameters(new ReportParameter("companyName", this.CompanyTitle));
                    //localReport.SetParameters(new ReportParameter("targetDate", this.TargetDate));
                    //localReport.SetParameters(new ReportParameter("LeftMainTitle", this.LeftMainTitle));
                    //localReport.SetParameters(new ReportParameter("LeftSubTitle", this.LeftSubTitle));
                    //localReport.SetParameters(new ReportParameter("ReportTitle", this.ReportTitle));
                    //localReport.SetParameters(new ReportParameter("ReportLogo", System.Web.HttpContext.Current.Server.MapPath(this.ReportLogo)));
                    //localReport.SetParameters(new ReportParameter("reportDate", this.ReportDate.ToShortDateString()));
                    //localReport.SetParameters(new ReportParameter("UserNamPrinting", this.UserNamPrinting));

                    //preparing to render the report

                    string reportType = this.Format.ToString();

                    string encoding;
                    string fileNameExtension;

                    //The DeviceInfo settings should be changed based on the reportType
                    //http://msdn2.microsoft.com/en-us/library/ms155397.aspx
                    string deviceInfo =
                    "<DeviceInfo>" +
                    "  <OutputFormat>" + this.Format.ToString() + "</OutputFormat>" +
                "  <PageWidth>8.5in</PageWidth>" +
                "  <PageHeight>8in</PageHeight>" +
                "  <MarginTop>0.5in</MarginTop>" +
                "  <MarginLeft>0.25in</MarginLeft>" +
                "  <MarginRight>0.25in</MarginRight>" +
                "  <MarginBottom>0.5in</MarginBottom>" +
                "</DeviceInfo>";

                    Warning[] warnings;
                    string[] streams;
                    byte[] renderedBytes;

                    //Render the report
                    renderedBytes = localReport.Render(
                         reportType,
                         deviceInfo,
                         out mimeType,
                         out encoding,
                        out fileNameExtension,
                         out streams,
                         out warnings);

                    return renderedBytes;

                }
                catch (Exception exc)
                {
                    throw exc;
                }
           }
    }

I want to give width size in report properties like below-- enter image description here

How can i give individual width to individual report or manage width dynamically? or In Report properties I want to set width and i want to get that width by code in reportViewModel.

"<PageWidth>some code to get width from report properties width</PageWidth>"

1 Answer 1

1

From MSDN I found this--enter image description here

It gave me clear idea that RDLC get all types of styles from Report Properties.It was not working for me because hardcode of "PageWidth" in DeviceInfo override the Report Properties Width.So the solution is to remove this

"  <PageWidth>8.5in</PageWidth>"

code from the deviceInfo.

Not the answer you're looking for? Browse other questions tagged or ask your own question.