我有一个外部共享点站点,我需要在其中更新大量文件的元数据。执行此操作的最佳方法似乎是使用列表 Web 服务,并使用 Lists.UpdateListItems
方法。但是,这种方法需要服务器上文档的ID,我没有这些信息。我确实有文档的文件路径/文件名。
使用名称/路径获取文档 ID 的最佳方法是什么?
最佳答案
如果您需要使用 Web 服务,您可能必须使用 SPQueries (CAML) 来获取您想要的项目。
Lists.asmx 网络服务(位于 http://sitecollection/_vti_bin/Lists.asmx 下)有一个名为 GetListItem 的函数以查询作为参数。
我真的不知道你的列表的内部工作原理,但像这样的查询应该可以做到:
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);
_sharepointSite 和 ListWS 对象是您的网络服务对象(它们应该在您添加网络引用时自动为您生成)。
listName 是您的列表在网站集上的名称
viewName 是您要查询的 View 的名称(如果您想查询所有内容,请确保您有一个显示所有元素的 View 。我通常依靠隐藏 View 来确保用户不会更改他们)
RowLimit 只是一个整数。
使用 Web 服务查找您正在处理的 Web 的 ID 应该没有问题。
您将返回的 XML 不是那么简单,需要特别注意。更多信息
请注意,如果您正在处理嵌套文件夹,则需要添加以下代码:
XmlNode queryOptionsNode = camlDocument.CreateElement("QueryOptions");
queryOptionsNode.InnerXml = "<ViewAttributes Scope=\"Recursive\" />";
关于我解释的更多信息here .
关于c# - 在 C# 中使用 Web 服务从共享点获取特定文档 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4166327/