是否可以在 SharePoint 中以编程方式将 Bamboo Web 部件添加到 Web 部件页面?

发布于 2024-09-01 07:31:18 字数 50 浏览 3 评论 0原文

根本找不到关于如何执行此操作的太多信息 - 如何添加 Web 部件,然后为其配置设置?

Can't find much information on how to do this at all - how can I add in a web part and then configure the settings for it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

紫竹語嫣☆ 2024-09-08 07:31:18

这是一个可以为您完成此操作的代码片段。在此示例中,我在页面上放置了一个内容编辑器 Web 部件,并以编程方式设置其内容。如果您想了解您的 Web 部件具有哪些属性,您可以手动将其放在页面上并将其导出。检查导出文件中的属性名称。
在您的情况下,必须引用第 3 方 DLL,并使用所需 Web 部件上的名称而不是 ContentEditorWebPart。您可以使用对象浏览器Reflector找到名称

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);
}

希望这有帮助。

Here's a code snippet that will do that for you. In this example, I put a Content Editor Web Part on the page and set the content of it programmatically. If you want to find out what properties your web part has, you can manually put it on a page and export it. Examine the exported file for the property names.
In your case, must must reference the 3rd party DLL, and use the name on the desired web part instead of the ContentEditorWebPart. You can find out the name by either using the Object Browser or Reflector.

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);
}

Hope this helps.

鯉魚旗 2024-09-08 07:31:18
  1. 通过对象模型加载要添加 Web 部件的页面。
  2. 获取 SPLimitedWebPartManager< /a> 此页面。
  3. 通过 AddWebPart() 添加所需的 Web 部件 方法。
  4. 如果您的 Web 部件使用普通 Web 部件配置,则您可以通过 Web 部件属性访问设置。
  1. Load the page you want to add the web part to via object model.
  2. Get the SPLimitedWebPartManager for this page.
  3. Add the web part you want via the AddWebPart() method.
  4. If your web part uses the normal web part configuration then you can access the settings via the web parts properties.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文