I am working with feature receivers in SP2010. I can successfully create web part pages and drop web part on the pages on feature activation.I was trying to add ReportViewerWeb Part (Integrated Mode) on the same page, but as soon as I create an instance of ReportViewerWebPart and no more code related to it, and try to deploy my feature I get an errror "Error on Activating Feature : object reference not set to an instance of an object". When I comment out the ReportViewerWebPart instance then no error.

Not sure where the problem lies.

Looking forward for your help.


public void CreateReportPages()

        string PagesLibrary = "Pages";// GetPagesLibraryName();
        string PagesLibraryUrl = "Pages/";// GetPagesLibraryUrl();
        ReportViewerWebPart rvWebPart = new ReportViewerWebPart();
        using (SPSite site = new SPSite(Constants.SiteURL))
            SPWeb web = site.OpenWeb();
            SPList list = web.Lists[PagesLibrary];

            //Custom web part
                ReportFilter reportFilter = new ReportFilter();

                string postInformation = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
                    + "<Method>"
                    + "<SetList Scope=\"Request\">" + list.ID + "</SetList>"
                    + "<SetVar Name=\"ID\">New</SetVar>"
                    + "<SetVar Name=\"Cmd\">NewWebPage</SetVar>"
                    + "<SetVar Name=\"Type\">WebPartPage</SetVar>"
                    + "<SetVar Name=\"WebPartPageTemplate\">1</SetVar>"
                    + "<SetVar Name=\"Title\">TestReport</SetVar>"
                    + "<SetVar Name=\"Overwrite\">true</SetVar>"
                    + "</Method>";

                    using (SPLimitedWebPartManager manager = web.GetLimitedWebPartManager(PagesLibraryUrl + "TestReport" + Constants.PageExtension, PersonalizationScope.Shared))

                        manager.AddWebPart(reportFilter, "", 0);

                        // manager.AddWebPart(rvWebPart, "", 1);

                       // manager.SaveChanges(rvWebPart);




Many Thanks VB

  • Typically, this is where the error is as SPContext (and others might not be available at the time of activation). Can you please share the source code. – ArkoD Jun 22 '12 at 6:46
  • The error comes only when I try to add the RVWP. In case of my custom web parts all works fine. – V.B Jun 22 '12 at 7:14
  • Did you verify the following :- 1) SharePoint Enterprise Features are activated in the site collection. 2) A report library with the content types for datasources has been already created before deployment. – ArkoD Jun 22 '12 at 11:02
  • I am not sure about the enterprise features but i can manually add ReportViewerWebaPart and the library where I am trying to add the page dynamically has Report Builder/Model/DataSources content type. – V.B Jun 25 '12 at 9:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.