集合中具有指定的名称、 视图字段、 查询、 行限制和指定的视图显示项目按页以及是否为默认视图的布尔值创建视图。
命名空间: 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 _
) 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 returnValue As SPView
returnValue = instance.Add(strViewName, _
strCollViewFields, strQuery, iRowLimit, _
bPaged, bMakeViewDefault)
public SPView Add(
string strViewName,
StringCollection strCollViewFields,
string strQuery,
uint iRowLimit,
bool bPaged,
bool bMakeViewDefault
)
参数
strViewName
类型:System.String一个包含视图的名称的字符串。
strCollViewFields
类型:System.Collections.Specialized.StringCollection一个包含视图字段的内部名称的集合。
strQuery
类型:System.String一个包含查询Where子句的协作应用程序标记语言字符串。
iRowLimit
类型:System.UInt32项在视图中返回的最大数目。指定的值大于Int32.MaxValue (2147483647 或十六进制 0x7FFFFFFF) 将引发异常,因为值超出范围。
bPaged
类型:System.Booleantrue 指定视图支持显示详细项目按页 ;否则为 false。
bMakeViewDefault
类型:System.Boolean若要使视图的默认视图 ; true 否则为 false。
返回值
类型:Microsoft.SharePoint.SPView
新的视图。
示例
下面的代码示例创建一个视图,返回的项,其中的字段值等于指定的文本值。
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><Eq>
<FieldRef Name='<iterm>Field3_Name</iterm>'/>" _
& "<Value Type='Text'><iterm>Text</iterm></Value></Eq></Where>"
views.Add(viewName, viewFields, query, 100, True, 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><Lt><FieldRef Name=\"Field3_Name\"/>" +
"<Value Type=\"Integer\">1000</Value></Lt></Where>";
collViews.Add(strViewName, collViewFields, strQuery, 100, true, false,
Microsoft.SharePoint.SPViewCollection.SPViewType.Grid, 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.