Search This Blog

Friday, February 4, 2011

Adding the WebPart in a Publishing Site Dynamically

When adding WebPart dynamically on a Publishing Site Page we need to define three things
1. WebPart to be Added
2. Zone
3. ZoneIndex
The Code Snippet is shown below:
SPLimitedWebPartManager manager = objFile.GetLimitedWebPartManager(System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
manager.AddWebPart(objWebPart, Zone, ZoneIndex);
  • Here objWebPart is the object of the WebPart to be added.
  • Zone is the zone where the WebPart is to added.
o Zones for default.aspx can be:
1. TopColumnZone
2. LeftColumnZone
3. RightColumnZone
o Zones for BlankWebPart.aspx Layout can be:
1. Header
2. TopLeftRow
3. TopRightRow
4. CenterLeftColumn
5. CenterColumn
6. CenterRightColumn
7. Footer
8. RightColumn
  • ZoneIndex is the index of the WebPart in that Particular Zone, by default its zero.

No comments:

Post a Comment