3 out of 21 rated this helpful - Rate this topic

Lists.UpdateList Method

Windows SharePoint Services 3
Updates a list based on the specified field definitions and list properties.

Web Service: ListsWeb Reference: http://<Site>/_vti_bin/Lists.asmx
[SoapDocumentMethodAttribute("http://schemas.microsoft.com/sharepoint/soap/UpdateList", RequestNamespace="http://schemas.microsoft.com/sharepoint/soap/", ResponseNamespace="http://schemas.microsoft.com/sharepoint/soap/", Use=SoapBindingUse.Literal, ParameterStyle=SoapParameterStyle.Wrapped)] 
public XmlNode UpdateList (
	string listName,
	XmlNode listProperties,
	XmlNode newFields,
	XmlNode updateFields,
	XmlNode deleteFields,
	string listVersion
)

Parameters

listName

A string that contains the GUID for the list.

listProperties

An XML fragment in the following form that can be assigned to a System.Xml.XmlNode object and that contains all the list properties to be updated.

<List Title="List_Name" Description="List_Description" 
    Direction="LTR"/>

The following table describes the attributes that can be used in the listProperties parameter.

Name

Description

AllowMultiResponses

TRUE to allow multiple responses to the survey.

Description

A string that contains the description for the list.

Direction

A string that contains LTR if the reading order is left-to-right, RTL if it is right-to-left, or None.

EnableAssignedToEmail

TRUE to enable assigned-to e-mail for the issues list.

EnableAttachments

TRUE to enable attachments to items in the list. Does not apply to document libraries.

EnableModeration

TRUE to enable Content Approval for the list.

EnableVersioning

TRUE to enable versioning for the list.

Hidden

TRUE to hide the list so that it does not appear on the Documents and Lists page, Quick Launch bar, Modify Site Content page, or Add Column page as an option for lookup fields.

MultipleDataList

TRUE to specify that the list in a Meeting Workspace site contains data for multiple meeting instances within the site.

Ordered

TRUE to specify that the option to allow users to reorder items in the list is available on the Edit View page for the list.

ShowUser

TRUE to specify that names of users are shown in the results of the survey.

Title

A string that contains the title of the list.

newFields

An XML fragment in the following form that can be assigned to a System.Xml.XmlNode object and that contains Field elements inside method blocks so that the add operations can be tracked individually.

<Fields>
   <Method ID="1">
      <Field ReadOnly="TRUE" Type="Counter" PrimaryKey="TRUE"
         DisplayName="Field1_Name" FromBaseType="TRUE" />
   </Method>
   <Method ID="2">
      <Field Type="Text" DisplayName="Field2_Name" 
         Required="TRUE" FromBaseType="TRUE" MaxLength="255" 
         Description="Description" /> 
   </Method>
   ...
</Fields>

To add a new field to a list view through the UpdateList method, use the AddToView attribute of the Method element to specify the GUID of the view.

Creating a calculated field is different from creating other fields because you must specify a formula, as in the following example, which creates a new field that concatenates the values of the Title and Created fields for each item.

<Fields>
   <Method ID="1">
      <Field Type="Calculated" DisplayName="myCalcField" ResultType="Text">
         <Formula>=Title&amp;Created</Formula>
         <FormulaDisplayNames>=Title&amp;Created</FormulaDisplayNames>
         <FieldRefs>
            <FieldRef Name="Title"/>
            <FieldRef Name="Created"/>
         </FieldRefs>
      </Field>
   </Method>
</Fields>

In the preceding example, the ampersand ("&") in the formula must be encoded for use in the SOAP request.

updateFields

An XML fragment in the following form that can be assigned to a System.Xml.XmlNode object and that contains Field elements inside method blocks so that the update operations can be tracked individually.

<Fields>
   <Method ID="3">
      <Field ReadOnly="TRUE" Type="Counter" Name="MyID" 
         PrimaryKey="TRUE" DisplayName="MyID" 
         FromBaseType="TRUE" />
   </Method>
   <Method ID="4">
      <Field Type="Text" Name="Title" DisplayName="DocTitle" 
         Required="TRUE" FromBaseType="TRUE" MaxLength="255" 
         Description="Title of your document" />
   </Method>
   ...
</Fields>
deleteFields

An XML fragment in the following form that contains Field elements specifying the names of the fields to delete inside method blocks so that the delete operations can be tracked individually.

<Fields>
   <Method ID="5">
      <Field Name="Field1" />
   </Method>
   <Method ID="6">
      <Field Name="Field2" />
   </Method>
   ...
</Fields>
listVersion

A string that contains the version of the list that is being updated so that conflict detection can be performed.

Return Value

An XML fragment that contains the list schema after changes are applied, and a results block for every field that is new, updated, or deleted. The fragment is in the following form and can be assigned to a System.Xml.XmlNode object.
<Results xmlns="http://schemas.microsoft.com/sharepoint/soap/">
   <NewFields>
      <Method ID="1">
         <ErrorCode>0x00000000</ErrorCode>
         <Field Type="DateTime" DateOnly="TRUE" 
            DisplayName="Field1_Display_Name" FromBaseType="TRUE" 
            Name="Field1_Name" ColName="datetime2" />
      </Method>
      <Method ID="2">
         <ErrorCode>0x00000000</ErrorCode>
         <Field Type="Text" DisplayName="Field2_Display_Name" 
            Required="TRUE" FromBaseType="TRUE" 
            Description="Description" Name="Field2_Name" 
            ColName="nvarchar4" />
      </Method>
   </NewFields>
   <UpdateFields>
      <Method ID="3">
         <ErrorCode>0x00000000</ErrorCode>
         <Field Type="Number" Name="NumberColumn" DisplayName="Numbers" 
            Required="TRUE" FromBaseType="TRUE" 
            Description="Description" ColName="float1" />
      </Method>
      <Method ID="4">
         <ErrorCode>0x00000000</ErrorCode>
         <Field Type="Text" Name="Title" DisplayName="Title" 
            Required="TRUE" FromBaseType="TRUE" 
            Description="Description" ColName="nvarchar1" />
      </Method>
   </UpdateFields>
   <DeleteFields>
      <Method ID="5">
         <ErrorCode>0x00000000</ErrorCode>
      </Method>
      <Method ID="6">
         <ErrorCode>0x00000000</ErrorCode>
      </Method>
   </DeleteFields>
   <ListProperties DocTemplateUrl="" 
      DefaultViewUrl="/Site_Name/Lists/List_Name/AllItems.aspx" 
      ID="{6800A6B5-5B01-4E7B-B847-7F0C01F1F602}" Title="List_Name" 
      Description="New_Description" 
      ImageUrl="/_layouts/images/itgen.gif" 
      Name="{6800A6B5-5B01-4E7B-B847-7F0C01F1F602}" BaseType="0" 
      ServerTemplate="100" 
      Created="20030619 05:35:34" Modified="20030619 05:39:43" 
      LastDeleted="20030619 05:35:34" 
      Version="11" Direction="none" ThumbnailSize="" WebImageWidth="" 
      WebImageHeight="" 
      Flags="4096" ItemCount="0" AnonymousPermMask="" 
      RootFolder="/Site_Name/Lists/List_Name" 
      ReadSecurity="1" WriteSecurity="1" Author="1" 
      EventSinkAssembly="" EventSinkClass="" 
      EventSinkData="" EmailInsertsFolder="" AllowDeletion="True" 
      AllowMultiResponses="False" 
      EnableAttachments="True" EnableModeration="False" 
      EnableVersioning="False" Hidden="False" 
      MultipleDataList="False" Ordered="False" ShowUser="True" />
</Results>

The following code example modifies the fields and properties of a specified list in the current site, showing how to implement each parameter of the UpdateList method. The example uses the GetList method to return the version of the list, and uses an XmlDocument object to create XmlNode objects for parameters.

This example requires that a using (Visual C#) or Imports (Visual Basic) directive be included for the System.Xml namespace.

Web_Reference_Folder.Lists listService = new Web_Reference_Folder.Lists();
listService.Credentials= System.Net.CredentialCache.DefaultCredentials;

XmlNode ndList = listService.GetList("List_Name");
XmlNode ndVersion = ndList.Attributes["Version"];

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

XmlNode ndDeleteFields = xmlDoc.CreateNode(XmlNodeType.Element, 
    "Fields", "");
XmlNode ndProperties = xmlDoc.CreateNode(XmlNodeType.Element, "List", 
    "");
XmlAttribute ndTitleAttrib = 
    (XmlAttribute)xmlDoc.CreateNode(XmlNodeType.Attribute, 
    "Title", "");
XmlAttribute ndDescriptionAttrib = 
    (XmlAttribute)xmlDoc.CreateNode(XmlNodeType.Attribute, 
    "Description", "");
XmlNode ndNewFields = xmlDoc.CreateNode(XmlNodeType.Element, 
    "Fields", "");
XmlNode ndUpdateFields = xmlDoc.CreateNode(XmlNodeType.Element, 
    "Fields", "");

ndTitleAttrib.Value = "List_Name";
ndDescriptionAttrib.Value = "New_Description";

ndProperties.Attributes.Append(ndTitleAttrib);
ndProperties.Attributes.Append(ndDescriptionAttrib);

ndDeleteFields.InnerXml="<Method ID='5'>" + 
   "<Field Name='Field1'/></Method>" + 
   "<Method ID='6'><Field Name='Field2'/>" + 
   "</Method>";

ndNewFields.InnerXml = "<Method ID='1'>" +
   "<Field Type='DateTime' DateOnly='TRUE' DisplayName='NewField1' 
        FromBaseType='TRUE'/>" + 
   "</Method><Method ID='2'>" +
   "<Field Type='Text' DisplayName='NewField2' Required='TRUE' 
      FromBaseType='TRUE' Description='Description'/>" +
   "</Method>";

ndUpdateFields.InnerXml = "<Method ID='3'>" +
   "<Field Type='Number' Name='Field1' DisplayName='Field1_Display' 
      Required='TRUE' FromBaseType='TRUE' 
      Description='Description'/>" +
   "</Method><Method ID='4'>" +
   "<Field Type='Text' Name='Field2' DisplayName='Field2_Display' 
      Required='TRUE' FromBaseType='TRUE' 
      Description='Description'/>" +
   "</Method>";

try
{
   XmlNode ndReturn = 
      listService.UpdateList("f2c47fbe-0fe1-4c84-8ed0-f56912f3dca7", 
      ndProperties, ndNewFields, ndUpdateFields, ndDeleteFields, 
      ndVersion.Value);

   MessageBox.Show(ndReturn.OuterXml);
}

catch (Exception ex)
{
   MessageBox.Show("Message:\n" + ex.Message + "\nStackTrace:\n" + 
      ex.StackTrace);
}
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Problem while adding question to survey
$0In my case this code did not work: (while adding new question to survey $0XmlNode ndNewFields = xmlDoc.CreateNode(XmlNodeType.Element,"Fields", "");$0 $0ndNewFields.InnerText = "<Method ID='1'>" +$0 $0                         "<Field Type='Note'  DisplayName='NEW NOTE CODE' FromBaseType='TRUE>" +$0 $0                         "</Method>";$0 $0$0 $0 $0I spent a lot of time on this. When I changed it to following code everything was fine:$0 $0System.Xml.XmlElement newElement = xmlDoc.CreateElement("Fields");$0 $0newElement.InnerXml = "<Method ID='1'>" +$0 $0                                   "<Field Type='Note'  DisplayName='NEW NOTE CODE' FromBaseType='TRUE'/> " +$0 $0   "</Method>";$0
Samples of how not to handle Version in the UpdateList method.

Hello,
Two common results from UpdateList are "...string not in a correct format" and "Your changes conflict...".
Both can be casued by <Version>Ver_integer<\Version>, when Ver_integer is submitted.
Particularly, when prototyping WebServices in non-standard toolsets and hardcoding some what-if values.
 Some rules are appropriate.
 
Rule1: Enclosing  "Ver_integer" in quotes RETURNS the error;  <errorstring>Input string was not in a correct format.</errorstring>
This can be confusing becuase successful list updates do return XML fragments including;    Version="10".
But the rule here is DO NOT USE QUOTES.  Other common issues include;
        Attempts to use  XX.YY  style versioning which is not permitted, and results in error; "not in a correct format."

Rule2:   Use  GETLIST 1st to find the next expected list VERSION first before making changes. 
The GETLIST VERSION reflects the next acceptable value for UPDATELIST to "avoid change conflicts". Other common issues include;
        Attempts to skip-over an integer value , results in a "conflict detection" error.
        Attempts to use a far earlier integer value , results in a "conflict detection" error.
        Simpler still is, not to declare Version. Because when the UpdateList method Version parameter is absent, the returned list "results block" still updates the Version integer correctly.

Hope that helps, because I spent many days learning that listProperties  XML fragments where not the source of errors. Instead it was an early hard coded Version value expressed in a non-standard development environment.

Microsoft.SharePoint.SoapServer.SoapServerException - Input string is not in a correct format.
Hello everyone,

I have tried everything and now am exclusively trying to run the sample code, and continue to get the following error back from the SharePoint 2010 Server:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><faultcode>soap:Server</faultcode><faultstring>Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown.</faultstring><detail><errorstring xmlns="http://schemas.microsoft.com/sharepoint/soap/">Input string was not in a correct format.</errorstring></detail></soap:Fault></soap:Body></soap:Envelope>

I have further looked at the SharePoint log itself, and this is what I have come across (using a ULS viewer):

SOAP exception: System.FormatException: Input string was not in a correct format.     at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)     at System.Number.ParseUInt32(String value, NumberStyles options, NumberFormatInfo numfmt)     at System.Convert.ToUInt32(String value)     at Microsoft.SharePoint.SoapServer.ListSchemaImpl.UpdateList(String strListName, String strListPropXML, String strNewFieldsXML, String strUpdateFieldsXML, String strDeleteFieldsXML, String ListVersion)     at Microsoft.SharePoint.SoapServer.ListSchemaValidatorImpl.UpdateList(String strListName, String strListPropXML, String strNewFieldsXML, String strUpdateFieldsXML, String strDeleteFieldsXML, String ListVersion)     at Microsoft.SharePoint.SoapServer.Lists.UpdateList(String listName, SoapXmlElement listProperties, SoapXmlElement newFields, SoapXmlElement updateFields, SoapXmlElement deleteFields, String listVersion)

At this point, I am simply running the example against my server. Note that I am able to fetch the list collection and add a new list without any issues, the problem arises when I try to use the UpdateList command. Both my code and the example in this article yield the same results.

Any help would be tremendously appreciated!

Update requirement
I am trying to update the display name of the filed Title that is created by default and I see that it only work successful if i put the atribute Type in the update XElement.

XElement nUpdateFields = new XElement("Fields", new XElement("Method", new XAttribute("ID", defList.Fields.Count.ToString()), new XElement("Field",
new XAttribute("Name", "Title"),
new XAttribute("Type","Text"),
new XAttribute("DisplayName", "Michel1"))));

before i did that i received web services exception.


Change ReadOnly attribute to FALSE can break view definitions!

If you try to set ReadOnly attribute of Modified field to FALSE:

ndUpdateFields.InnerXml = "<Method ID='1'><Field Type='DateTime' Name='Modified' ReadOnly='FALSE'/></Method>";

Then you will not be able to change any view or create one new.

Response for GetList method (after UpdateList calling):

HTTP/1.1 500 Internal Server Error
Date: Wed, 02 Dec 2009 13:50:05 GMT
Server: Microsoft-IIS/6.0
MicrosoftSharePointTeamServices: 12.0.0.6332
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Cache-Control: private
Content-Type: text/xml; charset=utf-8
Content-Length: 713

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><faultcode>soap:Server</faultcode><faultstring>Выдано исключение типа "Microsoft.SharePoint.SoapServer.SoapServerException".</faultstring><detail><errorstring xmlns="http://schemas.microsoft.com/sharepoint/soap/">Не удалось завершить эту операцию.
Повторите попытку.</errorstring><errorcode xmlns="http://schemas.microsoft.com/sharepoint/soap/">0x80004005</errorcode></detail></soap:Fault></soap:Body></soap:Envelope>

Delete does not work for field created using webservice
I was testing the code sample above and no matter what I do I cannot delete an attribute that I created using the Web Service.
Within Settings->Document Library Settings, Change Column there is no option to delete the column that has been created.
If I try the sample delete code above I get the following errors:
0x80004005Operation Failed for the Delete Operation and
0x82000007Field with that name was not found for the update operation

I managed to get the update working by passing in the entire field (as retrieved using the GetList() call). Presumably the update was failing because multiple fields were created with the same name. However I have no idea why the delete is not working.

<Field Type="DateTime" DateOnly="TRUE" DisplayName="NewField2" FromBaseType="TRUE" ID="{9dffc185-2875-4add-9427-01247a82f10e}" SourceID="{05fe2496-3ee6-4290-be7e-3a01133a5c1e}" StaticName="NewField10" Name="NewField10" ColName="datetime2" RowOrdinal="0" Version="8" xmlns="http://schemas.microsoft.com/sharepoint/soap/" />

There is nothing in the field definition that leads me to believe that it should be read only on non-deleteable.
Ideas anyone?

After trial and error I 'discovered' that the problem was the FromBaseType='TRUE' attribute.
Manually setting that to false before a delete allow the delete to work.
Still need to find out why though.
OnQuickLaunch
listProperties also supports an OnQuickLaunch boolean attribute to specify if the list should appear on the Quick Launch bar.
How to add a new field to the default view

Under newFields this article specifies that you can add an "AddToView" attribute to the Method element and specify the GUID of the view. As a convenience you can also just leave the GUID blank and the new field will be added to the default view. It'd look something like this:

XmlNode nodeFields = xmlDoc.CreateElement("Fields");
nodeFields.InnerXml = @"<Method ID='1' AddToView=''><Field Type='Text' DisplayName='Name' Required='TRUE' MaxLength='255' /></Method>";
Field Element Link Incorrect
Also, FYI, the "Field" element links in this article all go to the wrong place. They currently link to the view schema and they should link to the list schema. Here's where they should go:

http://msdn2.microsoft.com/en-us/library/ms437580.aspx
How to specify the order of appearance of the new field to the default view
How to specify the order of appearance of the new field to the default view?
If multiple views will use the new field, how to add the field to those multiple views?