0
votes

I am trying to add a webpart to aspx page webpart code is pasted below. I am able to see the content in the page, but it is not recognized as webpart.

 using (SPLimitedWebPartManager wpm = file.GetLimitedWebPartManager(System.Web.UI.WebControls.WebParts.PersonalizationScope.User))
  {
       foreach (WebPart wp in wpm.WebParts)
}

i am getting wpm.weparts.count=0 always until i customize the page and make it as un-ghosted.

may i know what i am doing it wrong here?

1

1 Answers

2
votes

You should use System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared instead of System.Web.UI.WebControls.WebParts.PersonalizationScope.User.

Shared: gives you all the webparts which is on the pages for all users

User: only gives you the webparts where the current user has made any personalization