sharepoint - 以编程方式将列表作为 Web 部件插入 WSS 3.0 的 Web 部件页面中

标签 sharepoint moss web-parts

我尝试在网上搜索以编程方式将列表作为 Web 部件插入到 Web 部件页面中,但并不幸运。

关于如何以编程方式将列表作为 web 部件插入 web 部件页面的任何想法或想法

非常感谢!

最佳答案

首先添加这些 using 语句。

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebPartPages;

然后在你的代码中

// First get the list
SPSite site = new SPSite("http://myserver");
SPWeb web = site.OpenWeb();
SPList list = web.Lists["MyCustomlist"];

// Create a webpart
ListViewWebPart wp = new ListViewWebPart();
wp.ZoneID = "Top";   // Replace this ith the correct zone on your page.
wp.ListName = list.ID.ToString("B").ToUpper();
wp.ViewGuid = list.DefaultView.ID.ToString("B").ToUpper();

// Get the web part collection
SPWebPartCollection coll = 
    web.GetWebPartCollection("default.aspx",    // replace this with the correct page.
    Storage.Shared);

// Add the web part
coll.Add(wp); 

如果你想使用自定义 View ,试试这个:

SPView view = list.GetUncustomizedViewByBaseViewId(0);
wp.ListViewXml = view.HtmlSchemaXml;

希望对你有帮助 W0ut

关于sharepoint - 以编程方式将列表作为 Web 部件插入 WSS 3.0 的 Web 部件页面中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1588019/

相关文章:

c# - 如何从本地 SharePoint 2013 和 ADFS 获取 FedAuth Cookie

javascript - 如何打印带有样式的表格

sharepoint - Access 2007 与 Sharepoint 2007 任务列表的集成

javascript - 获取 SharePoint 2007 客户端的当前用户名

sharepoint - 是否可以在 Office 2003 中隐藏 Web 文件属性对话框?

javascript - 如何从共享点列表中使用 javascript 显式加载列

sharepoint - 为什么我的 "out of the box"SharePoint 导航看起来像是在泄漏内存

sharepoint - 在 httpModules 节点的开头插入 SPWebConfigModification

c# - 如何修复文件下载后卡住页面?(TreeView SelectedNodeChanged中的TransmitFile)

css - Webpart 标题在编辑时可见,编辑后不可见