Thursday, September 17, 2015

Unable to cast object of type to'Microsoft.SharePoint.WebPartPages.WebPart'

Some of us face this issue while casting webparts in the page. Your code is like this when you get this error.

foreach (Microsoft.SharePoint.WebPartPages.WebPart item in wpManager.WebParts)
            {
                if (item.Title.Equals(webpartTitle))
                {
                    isExists = true;
                }

            }

Make like this

foreach (System.Web.UI.WebControls.WebParts.WebPart item in wpManager.WebParts)
            {
                if (item.Title.Equals(webpartTitle))
                {
                    isExists = true;
                }

            }

1 comment:

  1. I really enjoyed reading this post, big fan. Keep up the good work andplease tell me when can you publish more articles or where can I read more on the subject? SharePoint Intranet

    ReplyDelete