SPList.GetView 方法

返回基于指定 GUID 的列表视图。

命名空间:  Microsoft.SharePoint
程序集:  Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)

语法

声明
Public Function GetView ( _
    viewGuid As Guid _
) As SPView
用法
Dim instance As SPList
Dim viewGuid As Guid
Dim returnValue As SPView

returnValue = instance.GetView(viewGuid)
public SPView GetView(
    Guid viewGuid
)

参数

  • viewGuid
    类型:System.Guid

    标识视图的 GUID。

返回值

类型:Microsoft.SharePoint.SPView
视图。

备注

如果viewGuid参数的值为Empty,此方法将返回与当前用户可用的默认视图。

示例

下面的代码示例使用GetView方法可返回指定的列表视图,并将此视图传递为GetItems方法,以便返回并显示项目中的参数。

此示例使用ViewFields属性来获取显示的字段在列表中,然后用作索引为每个列表项。

此示例要求对Microsoft.SharePointMicrosoft.SharePoint.Utilities命名空间的using指令 (ImportsVisual Basic中)。

该示例假定存在的.aspx 页,其中包含一个名为Label1的标签控件。

Dim siteCollection As SPSite = SPContext.Current.Site
Try
    Dim srcList As SPList = siteCollection.AllWebs("Site_Name").Lists("List_Name")
    Dim srcViewGuid As Guid = srcList.Views("View_Name").ID
    Dim srcView As SPView = srcList.GetView(srcViewGuid)
    Dim viewFields As SPViewFieldCollection = srcView.ViewFields
    Dim srcItems As SPListItemCollection = srcList.GetItems(srcView)

    Dim srcItem As SPListItem
    For Each srcItem In  srcItems

        Dim i As Integer
        For i = 0 To viewFields.Count - 1
            Label1.Text += SPEncode.HtmlEncode(srcItem(viewFields(i)).ToString()) + " :: "
        Next i

        Label1.Text += "<BR>"
    Next srcItem

Finally
    siteCollection.Dispose() 
End Try
SPSite oSiteCollection = SPContext.Current.Site;
SPList oList = oSiteCollection.AllWebs["Site_Name"].Lists["List_Name"];
Guid guidViewID = oList.Views["View_Name"].ID;
SPView oViewSrc = oList.GetView(guidViewID);
SPViewFieldCollection collViewFields = oViewSrc.ViewFields;
SPListItemCollection collItemsSrc = oList.GetItems(oViewSrc);

foreach (SPListItem oItemSrc in collItemsSrc)
{
    for (int intIndex=0; intIndex<collViewFields.Count; intIndex++)
    {
        Label1.Text +=               SPEncode.HtmlEncode(oItemSrc[collViewFields[intIndex]].ToString()) 
         + " :: ";
    }
    Label1.Text += "<BR>";
}

另请参阅

引用

SPList 类

SPList 成员

Microsoft.SharePoint 命名空间