Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

Code

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>";
                web.ProcessBatchData(postInformation);


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

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


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


                        manager.SaveChanges(reportFilter);
                       // manager.SaveChanges(rvWebPart);


                    }




        }



    }

Many Thanks VB

share|improve this question
    
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. –  Arko D 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. –  Arko D 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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.