如何在Sharepoint 2010中以编程方式返回视图列表

时间:2011-03-30 18:16:30

标签: c# sharepoint sharepoint-2010

我找到了这个教程,但它在Vb中并且缺少太多东西,所以我不确定如何让它工作。

Here is a short example of how to get list views using Client object model in SharePoint 2010



Dim objmyList As SP.List = g_objCore.Security.Web.Lists.GetByTitle(“**Your List Name*”)

Dim objmyView As SP.View = objmyList.Views.GetByTitle(“*Your View Name*”)

Dim objViewFldColl As SP.ViewFieldCollection = objmyView.ViewFields

g_objCore.Security.ClientContext.Load(objViewFldColl)

g_objCore.Security.ClientContext.ExecuteQuery()

Now you can iterate through objViewFldColl to get the Fields in the View

我不确定如何获取此客户端对象模型。我也不知道要导入哪个List。我可以选择3个名称空间

using Microsoft.Office.Server.ActivityFeed;
using Microsoft.SharePoint.Portal.Audience.AdminUI;
using System.Windows.Documents;

我试图在后面的可视化Web部件代码中进行此操作。我正在使用C#,我实际上有5分钟的共享点经验(有点必须跳过101分享点并完成我现在临时的某个项目的这一小部分)。

1 个答案:

答案 0 :(得分:1)

您正在查看客户端OM(将从浏览器代码或客户端应用程序中使用)。对于Web部件中的代码,您应该使用服务器OM:SPList.Views - http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splist.views.aspx

SPContext.CurrentWeb.Lists[0].Views ...

之类的东西