开发者

Obtaining a specific document ID from sharepoint using web services in c#

开发者 https://www.devze.com 2023-01-25 07:32 出处:网络
I have an external sharepoint site, where I need to update the metadata of a large set of files. The best way to do this seems to be using the Lists web service, and using the Lists.UpdateListItems me

I have an external sharepoint site, where I need to update the metadata of a large set of files. The best way to do this seems to be using the Lists web service, and using the Lists.UpdateListItems method. However, this method requires the ID of the document on the server, information I don't have. I do have the filepath/filename of the开发者_开发知识库 document.

What is the best way to obtain the doc ID using its name/path?


If you need to go with the web service, you will probably have to go with SPQueries (CAML) to get the items you want.

The Lists.asmx web service (located under http://sitecollection/_vti_bin/Lists.asmx) has a function called GetListItem that takes a Query as a parameter.

I don't really know the inner workings of your list, but something like this query should do it :

XmlDocument camlDocument = new XmlDocument();
XmlNode queryNode = camlDocument.CreateElement("Query");
queryNode.InnerXml = "<Where>"
+ "<Eq><FieldRef Name='FileName' /><Value Type='Text'>{Your Filename Here}</Value></Eq>"
+ "</Where>";

XmlNode viewFieldsNode = camlDocument.CreateElement("ViewFields");
viewFieldsNode.InnerXml = "<FieldRef Name='ID' />";

XmlNode queryOptionsNode = camlDocument.CreateElement("QueryOptions");

resultNode = _sharepointSite.ListsWS.GetListItems(listName, viewName,
queryNode, viewFieldsNode, rowLimit, queryOptionsNode, webID);

The _sharepointSite and ListWS objects are your web serivce objects (they should be generated automatically for you when you add your web reference).

The listName is the name of your list on the site collection

The viewName is the name of the view you want to query on (make sure you have a view that shows all elements if you want to query on everything. I usually rely on hidden views to make sure that users don't change them)

RowLimit is just an int.

You should have no problem finding the ID of the web you are working on with the web service.

The XML that you will get back is not that straight forward and will need special attention. More informat

Note that if you are dealing with nested folders, you will want to add the following code :

XmlNode queryOptionsNode = camlDocument.CreateElement("QueryOptions");
queryOptionsNode.InnerXml = "<ViewAttributes Scope=\"Recursive\" />";

More information on what I explained here.

0

精彩评论

暂无评论...
验证码 换一张
取 消