This documentation is archived and is not being maintained.

Views.AddView Method

Windows SharePoint Services 3
Creates a view for the specified list.

Web Service: ViewsWeb Reference: http://<Site>/_vti_bin/Views.asmx

[SoapDocumentMethodAttribute("", RequestNamespace="", ResponseNamespace="", Use=SoapBindingUse.Literal, ParameterStyle=SoapParameterStyle.Wrapped)] 
public XmlNode AddView (
	string listName,
	string viewName,
	XmlNode viewFields,
	XmlNode query,
	XmlNode rowLimit,
	string type,
	bool makeViewDefault



A string that contains the internal name of the list.


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.


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:

  <FieldRef Name="Title" />
  <FieldRef Name="ID" />

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:

         <FieldRef Name="ID" />
         <Value Type="Counter">3</Value>
      <FieldRef Name="Title" />

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>

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


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

Return Value

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.
  <View Name="{B5C3250A-1974-49E9-9F61-180F86704434}" 
    DefaultView="TRUE" Type="HTML" DisplayName="All Contacts" 
    Url="Lists/Contacts/AllItems.htm" BaseViewID="1" xmlns=""> 
    <RowLimit Paged="TRUE">100</RowLimit>
      <FieldRef Name="LinkTitle" />
      <FieldRef Name="FirstName" />
      <FieldRef Name="Company" />
      <FieldRef Name="WorkPhone" />
      <FieldRef Name="HomePhone" />
      <FieldRef Name="Email" />
        <FieldRef Name="Title" />
        <FieldRef Name="FirstName" />

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.

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);