This is very nice....
You can add any default webpart with your modification into the webpart zone programatically.
(Am using TableOfContents.webpart to show the site map of your sharepoint site...)
using (SPLimitedWebPartManager wpm = web.GetLimitedWebPartManager(siteMapPage.Url, System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared))
{
#region Creating SiteMap Web Part
SPList wpGallery = site.GetCatalog(SPListTemplateType.WebPartCatalog);
foreach (SPListItem item in wpGallery.Items)
{
if (string.Compare(item.Name, "TableOfContents.webpart", true,
CultureInfo.InvariantCulture) == 0)
{
SPFile wpFile = item.File;
string errorMessage = String.Empty;
XmlReader reader = XmlReader.Create(wpFile.OpenBinaryStream());
TableOfContentsWebPart tocWP = new TableOfContentsWebPart();
tocWP = (TableOfContentsWebPart)wpm.ImportWebPart(reader, out errorMessage);
tocWP.ID = "wpTableOfContents";
wpm.AddWebPart(tocWP, "MiddleRightZone", 1);
tocWP.Title = "SiteMap Dialog";
// Initialize some properties on the web part
tocWP.AllowClose = false;
tocWP.AllowEdit = true;
tocWP.AllowHide = false;
tocWP.AllowZoneChange = false;
tocWP.AllowMinimize = false;
tocWP.ChromeType = System.Web.UI.WebControls.WebParts.PartChromeType.None;
wpm.SaveChanges(tocWP);
wpm.Web.Dispose();
}
}
#endregion
}
No comments:
Post a Comment