2

I am working on "Project Summary web part" Provisioning in wiki page as well as publishing page too.

Below is my code :

  ProjectSummaryWebPart newprojectSummaryWebPart = (ProjectSummaryWebPart)newWebPart;
                        Microsoft.SharePoint.Portal.WebControls.ProjectSummaryWebPart projectSummaryWebPart = new Microsoft.SharePoint.Portal.WebControls.ProjectSummaryWebPart();

                        projectSummaryWebPart.ID = webpartId;
                        projectSummaryWebPart.Title = newprojectSummaryWebPart.Title;
                        projectSummaryWebPart.AllowMinimize = newprojectSummaryWebPart.AllowMinimize;
                        projectSummaryWebPart.AllowZoneChange = newprojectSummaryWebPart.AllowZoneChange;
                        projectSummaryWebPart.AllowHide = newprojectSummaryWebPart.AllowHide;
                        projectSummaryWebPart.AllowClose = newprojectSummaryWebPart.AllowClose;
                        projectSummaryWebPart.ListId = newprojectSummaryWebPart.listID;



                        #region Set Panels In Project Summary Webpart
                        ProjectSummaryPanelConfig panelConfig = new ProjectSummaryPanelConfig();
                        panelConfig.IsLatePanel = newprojectSummaryWebPart.IsLatePanel;
                        if (newprojectSummaryWebPart.DaysToSearch > 0)
                        {
                            //Set DaystoSearch value to display tasks as per the latest due date.
                            //If due date is after 3 days and set value is 3 than only those task displayed in web part which has a due date after 3 days.
                            panelConfig.Enabled = true;
                            panelConfig.DaysToSearch = newprojectSummaryWebPart.DaysToSearch;


                        }
                        projectSummaryWebPart.Panels.Add(panelConfig);

I Want to set Panels value in web part. If i am provisioning web part without panel Values than it is working superb. But when i am set panels Value using "ProjectSummaryPanelConfig object" code gives me below error:

Error : System.NullReferenceException: Object reference not set to an instance of an object.

Can u help me out as soon as possible.

1

Please try as below it should work for you.

ProjectSummaryWebPart newprojectSummaryWebPart = (ProjectSummaryWebPart)newWebPart;
Microsoft.SharePoint.Portal.WebControls.ProjectSummaryWebPart projectSummaryWebPart = new Microsoft.SharePoint.Portal.WebControls.ProjectSummaryWebPart();

projectSummaryWebPart.ID = webpartId;
projectSummaryWebPart.Title = newprojectSummaryWebPart.Title;
projectSummaryWebPart.AllowMinimize = newprojectSummaryWebPart.AllowMinimize;
projectSummaryWebPart.AllowZoneChange = newprojectSummaryWebPart.AllowZoneChange;
projectSummaryWebPart.AllowHide = newprojectSummaryWebPart.AllowHide;
projectSummaryWebPart.AllowClose = newprojectSummaryWebPart.AllowClose;
projectSummaryWebPart.ListId = newprojectSummaryWebPart.listID;

#region Set Panels In Project Summary Webpart
projectSummaryWebPart.Panels = new List<ProjectSummaryPanelConfig>();
//Add below line in the code
ProjectSummaryPanelConfig panelConfig = new ProjectSummaryPanelConfig();
panelConfig.IsLatePanel = newprojectSummaryWebPart.IsLatePanel;
if (newprojectSummaryWebPart.DaysToSearch > 0)
{
    //Set DaystoSearch value to display tasks as per the latest due date.
    //If due date is after 3 days and set value is 3 than only those task displayed in web part which has a due date after 3 days.
    panelConfig.Enabled = true;
    panelConfig.DaysToSearch = newprojectSummaryWebPart.DaysToSearch;
}
projectSummaryWebPart.Panels.Add(panelConfig);

Let me know if it works.:)

Your Answer

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

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