Compartilhar via


Views.AddView Method

Creates a view for the specified list.

Namespace:  [Views Web service]
Web service reference: http://Site/_vti_bin/Views.asmx

Syntax

'Declaration
<SoapDocumentMethodAttribute("https://schemas.microsoft.com/sharepoint/soap/AddView", RequestNamespace := "https://schemas.microsoft.com/sharepoint/soap/",  _
    ResponseNamespace := "https://schemas.microsoft.com/sharepoint/soap/",  _
    Use := SoapBindingUse.Literal, ParameterStyle := SoapParameterStyle.Wrapped)> _
Public Function AddView ( _
    listName As String, _
    viewName As String, _
    viewFields As XmlNode, _
    query As XmlNode, _
    rowLimit As XmlNode, _
    type As String, _
    makeViewDefault As Boolean _
) As XmlNode
'Usage
Dim instance As Views
Dim listName As String
Dim viewName As String
Dim viewFields As XmlNode
Dim query As XmlNode
Dim rowLimit As XmlNode
Dim type As String
Dim makeViewDefault As Boolean
Dim returnValue As XmlNode

returnValue = instance.AddView(listName, _
    viewName, viewFields, query, rowLimit, _
    type, makeViewDefault)
[SoapDocumentMethodAttribute("https://schemas.microsoft.com/sharepoint/soap/AddView", RequestNamespace = "https://schemas.microsoft.com/sharepoint/soap/", 
    ResponseNamespace = "https://schemas.microsoft.com/sharepoint/soap/", 
    Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
public XmlNode AddView(
    string listName,
    string viewName,
    XmlNode viewFields,
    XmlNode query,
    XmlNode rowLimit,
    string type,
    bool makeViewDefault
)

Parameters

  • listName
    Type: System.String

    A string that contains the internal name of the list.

  • viewName
    Type: System.String

    A string that contains the GUID for the view, which determines the view to use for the default view attributes represented by the query, viewFields, and rowLimit parameters. If this argument is not supplied, the default view is assumed.

  • viewFields
    Type: System.Xml.XmlNode

    A ViewFields element that specifies which fields to return in the query and that can be assigned to a System.Xml.XmlNode object, as in the following example:

    <ViewFields>
      <FieldRef Name="Title" />
      <FieldRef Name="ID" />
    </ViewFields>
    
  • query
    Type: System.Xml.XmlNode

    A Query element containing the query that determines which records are returned and in what order, and that can be assigned to a System.Xml.XmlNode object. For example, the following query returns list items where the ID is less than 3 and orders the items by title:

    <Query>
      <Where>
          <Lt>
             <FieldRef Name="ID" />
             <Value Type="Counter">3</Value>
          </Lt>
       </Where>
       <OrderBy>
          <FieldRef Name="Title" />
       </OrderBy>
    </Query>
    
  • rowLimit
    Type: System.Xml.XmlNode

    A RowLimit element that specifies the number of items, or rows, to display on a page before paging begins, and that can be assigned to a System.Xml.XmlNode object. The fragment can include the Paged attribute to specify that the view return list items in pages. The following example sets a limit of 100 items per page:

    <RowLimit Paged="True">100</RowLimit>
    
  • type
    Type: System.String

    A string that specifies whether the view is an HTML view or a Datasheet view. Possible values include HTML and Grid.

  • makeViewDefault
    Type: System.Boolean

    true to make the view the default view for the list.

Return Value

Type: System.Xml.XmlNode
A Introduction to Collaborative Application Markup Language (CAML) fragment in the following form that contains the view schema and can be assigned to a System.Xml.XmlNode object.

<AddViewResult>
  <View Name="{B5C3250A-1974-49E9-9F61-180F86704434}" 
    DefaultView="TRUE" Type="HTML" DisplayName="All Contacts" 
    Url="Lists/Contacts/AllItems.htm" BaseViewID="1" > 
    <RowLimit Paged="TRUE">100</RowLimit>
    <ViewFields>
      <FieldRef Name="LinkTitle" />
      <FieldRef Name="FirstName" />
      <FieldRef Name="Company" />
      <FieldRef Name="WorkPhone" />
      <FieldRef Name="HomePhone" />
      <FieldRef Name="Email" />
    </ViewFields>
    <Query>
      <OrderBy>
        <FieldRef Name="Title" />
        <FieldRef Name="FirstName" />
      </OrderBy>
    </Query>
    <Aggregations></Aggregations>
    <Formats></Formats>
  </View>
</AddViewResult>

Examples

The following code example creates a view for a specified list that returns items in which the value of a DateTime field is greater than a specified date and time. This example requires that a using (C#) or Imports (Microsoft Visual Basic) directive be included for the System.Xml namespace.

Dim viewService As New Web_Reference_Folder.Views()
viewService.Credentials = System.Net.CredentialCache.DefaultCredentials

Dim strQuery As String = "<Where><Gt>" + _
    "<FieldRef Name="DateTime_Field" />" + _
    "<Value Type="DateTime">2003-6-10T12:00:00Z</Value>" + _
    "</Gt></Where>" + _
    "<OrderBy><FieldRef Name="Title" /></OrderBy>"
Dim strRowLimit As String = "50"
Dim strViewFields As String = "<FieldRef Name="Title" />" + _
    "<FieldRef Name="DateTime_Field" />"

Dim xmlDoc As New System.Xml.XmlDocument()

Dim ndQuery As System.Xml.XmlNode = xmlDoc.CreateNode(XmlNodeType.Element, "Query", "")
Dim ndRowLimit As System.Xml.XmlNode = xmlDoc.CreateNode(XmlNodeType.Element, "RowLimit", "")
Dim ndViewFields As System.Xml.XmlNode = xmlDoc.CreateNode(XmlNodeType.Element, "ViewFields", "")

ndQuery.InnerXml = strQuery
ndRowLimit.InnerXml = strRowLimit
ndViewFields.InnerXml = strViewFields

Dim retNode As XmlNode = viewService.AddView("List_Name", "View_Name", ndViewFields, ndQuery, ndRowLimit, "HTML", False)
Web_Reference_Folder.Views viewService = new Web_Reference_Folder.Views();
viewService.Credentials= System.Net.CredentialCache.DefaultCredentials;

string strQuery = "<Where><Gt><FieldRef Name=\"DateTime_Field\" />" +
   "<Value Type=\"DateTime\">2003-6-10T12:00:00Z</Value>" + "</Gt></Where>" +
   "<OrderBy><FieldRef Name=\"Title\" /></OrderBy>";

string strRowLimit = "50";

string strViewFields = "<FieldRef Name=\"Title\" />" +
"<FieldRef Name=\"DateTime_Field\" />";

System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();

System.Xml.XmlNode ndQuery = xmlDoc.CreateNode(XmlNodeType.Element, "Query","");
System.Xml.XmlNode ndRowLimit = xmlDoc.CreateNode(XmlNodeType.Element, "RowLimit","");
System.Xml.XmlNode ndViewFields = xmlDoc.CreateNode(XmlNodeType.Element, "ViewFields","");

ndQuery.InnerXml = strQuery;
ndRowLimit.InnerXml = strRowLimit;
ndViewFields.InnerXml = strViewFields;

XmlNode retNode = viewService.AddView("List_Name", "View_Name", ndViewFields, ndQuery, ndRowLimit ,"HTML", false);

See Also

Reference

Views Class

Views Members

Views Web Service