gpt4 book ai didi

SharePoint 2010 - 将可视化 Web 部件添加到页面 C#

转载 作者:行者123 更新时间:2023-12-01 12:59:53 24 4
gpt4 key购买 nike

我在 Visual Studio 2010 中创建了一个简单的可视化 Web 部件。我现在如何以编程方式将此 Web 部件添加到特定的 Sharepoint 2010 页面?我已经有了生成带有 ListView Web 部件的单栏 Wiki 页面的代码。

最佳答案

使用 SPLimitedWebPartManager对象

SPLimitedWebPartManager webPartManager = homePage.GetLimitedWebPartManager(System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
SPList announcementsList = currentWeb.Lists["Announcements"];
ListViewWebPart announcementsWebPart = new ListViewWebPart();
announcementsWebPart = new ListViewWebPart();
announcementsWebPart.Title = announcementsList.Title;
announcementsWebPart.ZoneID = "Left";
announcementsWebPart.ListName = announcementsList.ID.ToString("B").ToUpper();
announcementsWebPart.TitleUrl = announcementsList.DefaultViewUrl;
announcementsWebPart.ViewGuid = announcementsList.DefaultView.ID.ToString("B").ToUpper();
webPartManager.AddWebPart(announcementsWebPart, announcementsWebPart.ZoneID, 1);
webPartManager.SaveChanges(announcementsWebPart);

尝试 thisthis . Jan Tielens post , 而旧的仍然相关。

关于SharePoint 2010 - 将可视化 Web 部件添加到页面 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7151658/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com