How do I use ReportViewer 2010 in Visual Studio 2008 project?


 

Recently some customers asked me how to use reportviewer 2010 in their visual studio 2008 project. ReportViewer 2010 fully supports both Visual Studio 2008 and Visual Studio 2010. The problem is that in Visual Studio 2008, you cannot directly use it in design time. This is a helpful hint, so I decided to dig it out. Really it works very well but need your efforts on extracting the DLLs from GAC and manually coding to create the reportviewer control. Here are my steps to show you how to make it work.

1. Download the ReportViewer 2010 Redistributable package from http://www.microsoft.com/downloads/details.aspx?FamilyID=a941c6b2-64dd-4d03-9ca7-4017a0d164fd&displaylang=en.

2. Install it on your computer, then the Microsoft.ReportViewer.WinForm.dll will be registered in GAC, however you could not directly reference this assembly from GAC in Visual Studio 2008. Referencing the assembly file is needed however the dll is not installed in other place. So the next step is how to extract the assembly file from the GAC.

3. John’s blog showed some ways to extract assemblies from GAC. I used Windows Command Prompt to extract the Microsoft.ReportViewer.Winform.dll and Microsoft.ReportViewer. Common.dll out to my project’s bin folder. You can first use the “cd” command to redirect the folder to ” C:\Windows\assembly\GAC_MSIL\Microsoft.ReportViewer.WinForms”, then use the “dir” command to check which folder is for ReportViewer 10.0 and run “cd” again to redirect to that folder, then run copy command like “copy Microsoft.ReportViewer.Winform.dll D:\Projects\MyTestReport\Bin\Microsoft.ReportViewer.Winform.dll” to copy the file to your project’s bin folder. As well you can copy the Microsoft.ReportViewer. Common.dll file.

4. Then in Visual Studio 2008, right click the Reference folder, click “Add Reference…”, switch to the Browse tab and add the references to these two assemblies. You can also add the ReportViewer control to the ToolBox via Choose Items by selecting the assembly Microsoft.ReportViewer.Winform.dll in the bin folder, but you will find that the control does not have real UI appearance. It just shows as a component but it is good since you can set properties via the property window.

5. Refer to those auto-generated code for the ReportViewer 2008 control in your project, manually add the code for your Reportviewer 2010 control to your Windows Form application accordingly.

6. For example, you have a form named Form1, modify the InitializeComponent function in Form1.Designer.cs as follows.

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support – do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();

            this.reportViewer1 = new Microsoft.Reporting.WinForms.ReportViewer();
            adventureWorksDW2008DataSet = new AdventureWorksDW2008DataSet();
            V_GETSALESTableAdapter = new WFMix.AdventureWorksDW2008DataSetTableAdapters.v_getSalesTableAdapter();

            this.SuspendLayout();
            //
            // reportViewer1
            //
            this.reportViewer1.LocalReport.ReportEmbeddedResource = “WFMix.Report1.rdlc”;
            //this.reportViewer1.LocalReport.ReportPath = “Report1.rdlc”;
            this.reportViewer1.Location = new System.Drawing.Point(13, 13);
            this.reportViewer1.Name = “reportViewer1”;
            this.reportViewer1.Size = new System.Drawing.Size(532, 352);
            this.reportViewer1.TabIndex = 0;

            Microsoft.Reporting.WinForms.ReportDataSource rds = new Microsoft.Reporting.WinForms.ReportDataSource();
            rds.Name = “AdventureWorksDW2008DataSet_v_getSales”;
            rds.Value = adventureWorksDW2008DataSet.v_getSales;
            this.reportViewer1.LocalReport.DataSources.Add(rds);

            //
            // Form1
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(708, 417);
            this.Controls.Add(this.reportViewer1);
            this.Name = “Form1”;
            this.Text = “Form1”;
            this.Load += new System.EventHandler(this.Form1_Load);
            this.ResumeLayout(false);

        }

        #endregion

        private Microsoft.Reporting.WinForms.ReportViewer reportViewer1;
        private AdventureWorksDW2008DataSet adventureWorksDW2008DataSet = null;
        private AdventureWorksDW2008DataSetTableAdapters.v_getSalesTableAdapter V_GETSALESTableAdapter = null; 

7. In the Form_Load event, you can fill the data to refresh your report just like ReportViewer 2008. 

 

        private void Form1_Load(object sender, EventArgs e)
        {
            V_GETSALESTableAdapter.Fill(adventureWorksDW2008DataSet.v_getSales);
            this.reportViewer1.RefreshReport();
        }

Comments (8)

  1. Raj says:

    Thanks for the article. but In my case, I have report and other controls in same winform. how can i refresh the report?. any help would be appreciated. thanks

  2. wW1711 says:

    Once I "dir" at …Microsoft.ReportViewer.WinForms I'm not seeing a location to further "cd" into…

    The columns I see (in PS) are "Mode", "LastWriteTime", "Length" , and "Name".

    No folder…

    Any ideas?

  3. wW1711 says:

    Oh, and the "Name" field doesn't appear to be a folder… It looks like the Public Key Token…

  4. Jorge Olimpia says:

    Thank you for the article Charles. I got your tips and use them in a ASP.NET project, adapting what was necessary to work. For those who want to try it, after install Report Viewer 10 Redistributable package, copy Microsoft.Report.Common.dll and Microsoft.Report.WebForms.dll to other folder and reference both files in your project. After that, in the web.config file change the references from 9.0.0.0 to 10.0.0.0 Report Viewer's version. Also, change the version number in the web form where you add the component.

    Regards.

  5. Mark73 says:

    Hi,

    Is there a way that i can use the RSRemoteRpcClient in vs2010 communicating with sql 2008 r2?

    Now i can only use this on the 9.0 reference..but not on the 10.0.

    is there a way to work arround this?

    Best regards,

    Mark

  6. solange says:

    Hola, yo trabajo en asp.net 2008 con visual, hice todos los pasos de Jorge Olimpia, pero no encuentro como acceder a desinger.vb para modificar el codigo, hay alguna manera de poder ver y modificar el desinger.vb  para webforms ?

    Saludos

  7. solange says:

    Hola, yo trabajo en asp.net 2008 con visual, hice todos los pasos de Jorge Olimpia, pero no encuentro como acceder a desinger.vb para modificar el codigo, hay alguna manera de poder ver y modificar el desinger.vb  para webforms ?

    Saludos

  8. Jason says:

    I know this post is a year old, but thank you so much!!!!!

Skip to main content