创建集合中具有指定的名称、 视图字段、 查询、 行限制、 布尔值指定的视图显示项目按页以及它是否为默认视图、 视图类型和一个布尔值,指定视图是否个人或公共视图。
命名空间: Microsoft.SharePoint
程序集: Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)
语法
声明
Public Function Add ( _
strViewName As String, _
strCollViewFields As StringCollection, _
strQuery As String, _
iRowLimit As UInteger, _
bPaged As Boolean, _
bMakeViewDefault As Boolean, _
type As SPViewCollection.SPViewType, _
bPersonalView As Boolean _
) As SPView
用法
Dim instance As SPViewCollection
Dim strViewName As String
Dim strCollViewFields As StringCollection
Dim strQuery As String
Dim iRowLimit As UInteger
Dim bPaged As Boolean
Dim bMakeViewDefault As Boolean
Dim type As SPViewCollection.SPViewType
Dim bPersonalView As Boolean
Dim returnValue As SPView
returnValue = instance.Add(strViewName, _
strCollViewFields, strQuery, iRowLimit, _
bPaged, bMakeViewDefault, type, bPersonalView)
public SPView Add(
string strViewName,
StringCollection strCollViewFields,
string strQuery,
uint iRowLimit,
bool bPaged,
bool bMakeViewDefault,
SPViewCollection.SPViewType type,
bool bPersonalView
)
参数
strViewName
类型:System.String一个包含视图的名称的字符串。
strCollViewFields
类型:System.Collections.Specialized.StringCollection一个包含视图字段的内部名称的集合。
strQuery
类型:System.String协作应用程序标记语言 (CAML)字符串,包含查询Where子句。
iRowLimit
类型:System.UInt32项在视图中返回的最大数目。指定的值大于 Int32.MaxValue (2147483647 或十六进制 0x7FFFFFFF) 将引发异常,因为值超出范围。
bPaged
类型:System.Booleantrue指定视图支持显示详细项目按页 ;否则为false。
bMakeViewDefault
类型:System.Boolean若要使视图的默认视图 ; true否则为false。
type
类型:Microsoft.SharePoint.SPViewCollection.SPViewType枚举值,指定视图的类型。
bPersonalView
类型:System.Booleantrue创建个人视图 ;false ,若要创建的公共视图。
返回值
类型:Microsoft.SharePoint.SPView
新的视图。
异常
| 异常 | 条件 |
|---|---|
| InvalidOperationException | 指定的视图类型为列表模板类型无效。 |
示例
下面的代码示例创建一个网格视图,并显示其中一个字段值是小于 1000 的项。
Dim siteCollection As SPSite = SPControl.GetContextSite(Context)
Dim site As SPWeb = siteCollection.AllWebs("Site_Name")
Dim list As SPList = site.Lists("List_Name")
Dim views As SPViewCollection = list.Views
Dim viewName As String = "View_Name"
Dim viewFields As New System.Collections.Specialized.StringCollection()
viewFields.Add("Field1_Name")
viewFields.Add("Field2_Name")
viewFields.Add("Field3_Name")
Dim query As String = "<Where><Lt><FieldRef Name='<iterm>Field3_Name</iterm>'/>" _
& "<Value Type='Integer'>1000</Value></Lt></Where>"
views.Add(viewName, viewFields, query, 100, True, False, Microsoft.SharePoint.SPViewCollection.SPViewType.Grid, False)
SPSite oSiteCollection = SPContext.Current.Site;
using (SPWeb oWebsite = oSiteCollection.AllWebs["Website_Name"])
{
SPList oList = oWebsite.Lists["List_Name"];
SPViewCollection collViews = oList.Views;
string strViewName = "View_Name";
System.Collections.Specialized.StringCollection collViewFields = new System.Collections.Specialized.StringCollection();
collViewFields.Add("Field1_Name");
collViewFields.Add("Field2_Name");
collViewFields.Add("Field3_Name");
string strQuery = "<Where><Eq><FieldRef Name=\"Field3_Name\"/>" +
"<Value Type=\"Text\">Text</Value></Eq></Where>";
collViews.Add(strViewName, collViewFields, strQuery, 100, true, false);
}
备注
Certain objects implement the IDisposable interface, and you must avoid retaining these objects in memory after they are no longer needed. For information about good coding practices, see Disposing Objects.