简体   繁体   中英

Sharepoint webpart in aspx page -markup

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM