Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
Article ID: 923902 - Last Review: May 14, 2007 - Revision: 2.4
Values that were previously associated with a field are reset when you run a custom code that calls the Lists.UpdateList method to update a list view in SharePoint Products and Technologies
Consider the following scenario. In one of the products that are listed in the "Applies to" section, you create a custom code that references the List.asmx Web service. The code calls the
Lists.UpdateList method and adds a field to a list view. The code then updates a property of the field. For example, the code updates the display name of the field. However, when you run the code, the property of the field is not updated as expected. Instead, all the values that were previously associated with the field are reset.
The following code is an example of a code in which you experience these symptoms:
// Initialisation - BEGINS
PostLists.Lists lst = new TESTBED.PostLists.Lists();
lst.Credentials = System.Net.CredentialCache.DefaultCredentials;
XmlNode ndList = lst.GetList("ListName");
XmlNode ndVersion = ndList.Attributes["Version"];
XmlDocument xmlDoc = new System.Xml.XmlDocument();
XmlNode ndProperties = xmlDoc.CreateNode(XmlNodeType.Element, "List", "");
XmlNode ndDeleteFields = xmlDoc.CreateNode(XmlNodeType.Element,"Fields","");
XmlNode ndNewFields = xmlDoc.CreateNode(XmlNodeType.Element,"Fields","");
XmlNode ndUpdateFields = xmlDoc.CreateNode(XmlNodeType.Element,"Fields","");
XmlAttribute ndTitleAttribute = (XmlAttribute)xmldoc.CreateNode(XmlNodeType.Attribute, "Title", "");
XmlAttribute ndDescriptionAttribute = (XmlAttribute)xmldoc.CreateNode(XmlNodeType.Attribute, "Description", "");
ndTitleAttribute.Value="ListName";
ndDescriptionAttribute.Value="Description";
ndProperties.Attributes.Append(ndTitleAttribute);
ndProperties.Attributes.Append(ndDescriptionAttribute);
// Initialisation - ENDS
// STEP1: Add a new Field
ndNewFields.InnerXml = "<Method ID='1'>" +
"<Field Type='DateTime' Name='testNewField1' DisplayName='testNewField1 description'>" +
" </Method>";
// STEP1.1: Call the Lists.UpdateList method
XmlNode ndReturn =
lst.UpdateList("{18D0E90B-20B9-4931-96EB-5435D08532DC}",
ndProperties, ndNewFields, null , null,
ndVersion.Value);
MessageBox.Show(ndReturn.OuterXml);
// STEP2: Update that field
ndUpdateFields.InnerXml = "<Method ID='2'>" +
"<Field Type='DateTime' Name='testNewField1' DisplayName='Field1'/>" +
"</Method>";
// STEP2.1: Call the Lists.UpdateList method
XmlNode ndReturn =
lst.UpdateList("{18D0E90B-20B9-4931-96EB-5435D08532DC}",
ndProperties, null, ndUpdateFields , null,
ndVersion.Value);
MessageBox.Show(ndReturn.OuterXml);
This problem occurs because the Lists.asmx Web service assigns null values to all values that are not explicitly passed in the update operation.
To work around this problem, use the Lists.asmx Web service to update the property of the field. To do this, note the original values of the field. Then, when you update the field, pass the original values in addition to the updated values.
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.
For more information about the
Lists.UpdateList method, visit the following Microsoft Web site:
APPLIES TO
- Microsoft Office SharePoint Server 2007
- Microsoft Office SharePoint Portal Server 2003
- Microsoft Windows SharePoint Services 3.0
- Microsoft Windows SharePoint Services 2.0
| kbtshoot kbprb kbexpertiseinter KB923902 |
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate