Saturday, November 14, 2009

Error and Resolution using SharePoint List web service

Problem #1
I have used the following code to connect to SharePoint list and upload data
Reference the SharePoint web service as ListService
http://servername:9000/_vti_bin/lists.asmx


ListService.ListsSoapClient addlist = new ListService.ListsSoapClient();
addlist.ClientCredentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;
addlist.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
addlist.Endpoint.Address = new System.ServiceModel.EndpointAddress(sharePointServerUrl + "/_vti_bin/Lists.asmx");
// Input Data for the list
XmlDocument doc = new XmlDocument();
XmlElement batch = doc.CreateElement("Batch");

// NEw in the above XMl for new Element addtion
XmlElement result = addlist.UpdateListItems("share Point ListName" , batch);
Issue #1
I got the Error message "Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown. "
Solution #1
The sharePoint list name in the UpdateListItems method was incorrect and changed that, then worked well for me.

Issue #2
XmlElement result = addlist.UpdateListItems("share Point ListName" , batch);
result.InnerText shows "0x81020014One or more field types are not installed properly. Go to the list settings page to delete these fields." and the list was not updated properly
Solution #2
The issue is due to the non usage of internal names for the field names. So check the internal name of the fields in the list and changed accordingly as below. In the input XML (batach.InnerXml) , use Field Name='Last_x0020_Name' (This is the internal name of the field) instead of Field Name='Last Name'. Use internal names for the field instead of display names. This worked for me.
Also check the case of the internal field name( LastName and Lastname are different). Use the correct casing in field name to work properly.
Issue #3
addlist.UpdateListItems("share Point ListName" , batch);
Error while updating the list item
0x80070005The operation failed because an unexpected error occurred. (Result Code: 0x80070005)
Solution #3
The list doesn't have update access to the user. Providing access to the list solves this issue