[英]Is it possible to add Bamboo Web Parts to a web part page programmatically in SharePoint?
無法找到有關如何執行此操作的詳細信息 - 如何添加Web部件然后為其配置設置?
這是一個代碼片段,可以幫助您。 在此示例中,我在頁面上放置了內容編輯器Web部件,並以編程方式設置其內容。 如果要查找Web部件具有的屬性,可以手動將其放在頁面上並導出。 檢查導出的文件以獲取屬性名稱。 在您的情況下,必須引用第三方DLL,並使用所需Web部件上的名稱而不是ContentEditorWebPart
。 您可以使用Object Browser
或反射器找到名稱。
SPFile spPageFile = web.GetFile(targetFilePath);
using (SPLimitedWebPartManager theMan = spPageFile.GetLimitedWebPartManager(PersonalizationScope.Shared))
{
ContentEditorWebPart cewp = new ContentEditorWebPart();
cewp.ChromeType = PartChromeType.None;
XmlDocument xmlDoc = new XmlDocument();
XmlElement xmlEl = xmlDoc.CreateElement("NewCEWP");
xmlEl.InnerText = string.Format(@"<h2>Blah blah blah...</h2>");
cewp.Content = xmlEl;
theMan.AddWebPart(cewp, "Main", 0);
theMan.SaveChanges(wp);
}
希望這可以幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.