I’m trying to update some metadata with web services. I read following msdn article UpdateListItems and wrote a small test program, but sadly something went wrong. I get the error message, that the list is not found where I would like to change something. I would like to modify the metadata in a document library not only in a list.
If I execute XmlNode test = listService.GetList("{3c5c1ebd-1f19-4223-b162-e3d200c903f5}"); I get the attributes from the list. Everything looks fine, connection and so one works...
I create a new Batch to update the library with following attributes:
Batch.SetAttribute("OnError","Continue");
Batch.SetAttribute("PreCalc", "true");
Batch.SetAttribute("ListVersion","0");
Batch.SetAttribute("RootFolder", rootFolder);
rootFolder is test.Attributes["RootFolder"].Value + "/LibraryName";
The string batch looks like:
"<Method ID='1' Cmd='Update'>" +
"<Field Name='ID'>6VJWEENCP2DC-250-33</Field>" +
"<Field Name='Status'>1</Field></Method>";
What went wrong? Why would the list not be updated?
I get following error:
<Results xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<Result ID="1,Update">
<ErrorCode>0x81020026</ErrorCode>
<ErrorText>...List does not exist...</ErrorText>
</Result>
</Results>
Edit Here a little bit more code.
webportal.Lists listService = new webportal.Lists();
listService.Credentials = System.Net.CredentialCache.DefaultCredentials;
XmlNode test = listService.GetList("{3c5c1ebd-1f19-4223-b162-e3d200c903f5}");
string rootFolder = test.Attributes["RootFolder"].Value + "/Library Name";
string strBatch =
"<Method ID='1' Cmd='Update'>" +
"<Field Name='ID'>6VJWEENCP2DC-250-34</Field>" +
"<Field Name='Name_x002C__x0020_Firstname'>Yeahaa!</Field></Method>";
XmlDocument xmlDoc = new System.Xml.XmlDocument();
System.Xml.XmlElement elBatch = xmlDoc.CreateElement("Batch");
elBatch.SetAttribute("OnError","Continue");
elBatch.SetAttribute("PreCalc", "true");
elBatch.SetAttribute("ListVersion","1");
elBatch.SetAttribute("RootFolder", rootFolder);
//elBatch.SetAttribute("ViewName", "{8e208951-1455-46de-9566-032de23fb2d9}");
elBatch.InnerXml = strBatch;
XmlNode ndReturn = listService.UpdateListItems("{3c5c1ebd-1f19-4223-b162-e3d200c903f5}", elBatch);
Edit2
Now I have changed my code and I’m using the client object model. The access to the libraries works very well. Now I would like to access to the folder in the library and change the metadata there.
But if I change the siteurl to the folder path, I get an exception that the _vti_bin/sites.asmx is not found.
Here is my code (working code for libraries):
string siteurl = "http://webportal/dokumente/site";
ClientContext clientContext = new ClientContext(siteurl);
Web site = clientContext.Web;
clientContext.Load(site, s => s.Title);
clientContext.ExecuteQuery();
List list = clientContext.Web.Lists.GetByTitle("library");
CamlQuery query = new CamlQuery();
query.ViewXml =
@"<View>
<Query>
<Where>
<Eq>
<FieldRef Name='Title' />
<Value Type='Text'>test</Value>
</Eq>
</Where>
</Query>
</View>";
ListItemCollection list2 = list.GetItems(query);
clientContext.Load(list2);
clientContext.ExecuteQuery();
How could I fix this? How could I access to the folder and change the metadata?