This tip come from one of my colleagues, but it’s a good ‘un:
For those of you familiar with the Lists.asmx web service in SharePoint, you’ll know that the UpdateListItems() method allows you to apply metadata to a list item. The following XML provides a simple example of how I’ve been using it so far….
<Method ID=’1’ Cmd=’Update’>
<Field Name=’ID’ />
<Field Name=’FileRef’>http://site/library/folder1/folder2/mydoc.pdf</Field>
<Field Name=’ContentType’>Invoice</Field>
<Field Name=’InvoiceNumber’>12345</Field>
</Method>
Under normal circumstances, the above XML works just fine. However, if you enable fine grained permissions [Item Level Permissions] in a document library it will break with a permissions related error (even though you have permissions to perform the action!)In this situation what you MUST do is also pass in a value for the ID field, otherwise it won’t work. E.g.:
<Method ID=’1’ Cmd=’Update’>
<Field Name=’ID’ >57</Field>
<Field Name=’FileRef’>http://site/library/folder1/folder2/mydoc.pdf</Field>
<Field Name=’ContentType’>Invoice</Field>
<Field Name=’InvoiceNumber’>12345</Field>
</Method>
If you’re performing a HTTP PUT to upload your document, you won’t know the ID value, so you’ll need make another web service call to retrieve it. E.g.
XmlNode query = xmlDoc.CreateNode(XmlNodeType.Element, "Query", string.Empty);
query.InnerXml = "<Where><Eq><FieldRef Name='FileRef'/><Value Type='Note'>" + EscapeXmlValue(uri.Path.Substring(1)) + "</Value></Eq></Where>";
XmlNode viewFields = xmlDoc.CreateNode(XmlNodeType.Element, "ViewFields", string.Empty);
viewFields.InnerXml = "<FieldRef Name='ID'/>";
XmlNode queryOptions = xmlDoc.CreateNode(XmlNodeType.Element, "QueryOptions", string.Empty);
queryOptions.InnerXml = "<QueryOptions><ViewAttributes Scope='Recursive' /></QueryOptions>";
XmlNode node = _listsWebService.GetListItems(listGuid, null, query, viewFields, "1", queryOptions, null);
XmlNodeList items = node.SelectNodes("rs:data/z:row", _nsm);
if (items.Count == 0) {
return null;
} else {
//document found. Return the ID
return items[0].Attributes["ows_ID"].Value;
}
}
I would recommend that peeps check through their code to see where they use the UpdateListItem() method and make sure they’re populating the ID value; otherwise things could go pop when the customer switches on fine grained permissions.
By “enable fine grained permissions [Item Level Permissions]” -do you mean that you changed a specific item’s security in the library or do you mean the library itself is no longer inheriting from the site?
I have a situation very similar to yours -except that the ContentType field “refuses” to change. All calls result in the content type being set to the library’s default content type regardless of what I pass in. My library is not inheriting form the site.
Any thoughts?
thanks,
Dan
Hi Dan,
I mean that the Items no longer inherits permissions from the Library – so yes, we changed a specific item’s security without affecting security for other items in the library. Once you’ve done that, by the way, that library ALWAYS has fine grained permissions, even if you change the permissions back.
Anyway, to your question – what message do you get back from the web service? Would it be something like the document is uploaded as a default content type and checked in? Then you update on the content type & metadata might be refused ‘cos checkout was required.
Are you updating an item that you just uploaded or something?
It does not work !!!
the xml missing the Batch tag For exmp
befor Method Tag
Well, yes. I don’t know what else you might be wanting to do in the Batch. You’ve got to figure out some of what you want to do yourself! But the code I’ve posted was the core of what I was having to do, and it worked for me