共用方式為


SPViewCollection.Add method (String, StringCollection, String, UInt32, Boolean, Boolean)

建立具有指定的名稱、 檢視欄位、 查詢、 資料列限制和布林值,以指定檢視顯示項目] 頁面的頁面以及它是否為預設檢視集合中的檢視。

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

'宣告
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
    Type: System.String

    字串,包含檢視的名稱。

  • iRowLimit
    Type: System.UInt32

    若要在檢視中傳回的項目最大數目。指定的值大於Int32.MaxValue (2147483647 或十六進位的 0x7FFFFFFF),因為值超出範圍,會擲回例外狀況。

  • bPaged
    Type: System.Boolean

    若要指定檢視支援顯示更多的項目頁面 ; true 否則, false。

  • bMakeViewDefault
    Type: System.Boolean

    true ,讓該檢視的預設檢視。否則, false。

傳回值

Type: Microsoft.SharePoint.SPView
新的檢視。

Examples

下列程式碼範例會建立傳回項目欄位的值等於指定之文字值的其中一個檢視。

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);
}
注意事項注意事項

某些物件實作IDisposable介面,並且您必須避免之後不再需要保留這些物件在記憶體中。良好的程式碼撰寫方式的相關資訊,請參閱Disposing Objects

請參閱

參照

SPViewCollection class

SPViewCollection members

Add overload

Microsoft.SharePoint namespace