[英]How to get single item from SharePoint document library using SPQuery (without using for loop)?
Sometimes there is a requirement to get only one SharePoint item from a large document library. 有时需要从大型文档库中仅获取一个SharePoint项目。 So, how to get single item from SharePoint document library using SPQuery (without using for loop)?
那么,如何使用SPQuery从SharePoint文档库中获取单个项目(不使用for循环)?
SPList class has several methods for getting only single item: SPList类具有几种仅获取单个项目的方法:
Except the last one they need integer ID (ID property of SPListItem) of item. 除了最后一个之外,它们还需要项的整数ID(SPListItem的ID属性)。 The last one uses the guid ID (UniqueId property of SPListItem).
最后一个使用GUID ID(SPListItem的UniqueId属性)。
Here is the C# code to achieve the above requirement: 这是达到上述要求的C#代码:
public SPListItemCollection GetSpecificLibraryItem(fileName)
{
SPList list = web.Lists["MyDocName"];
SPQuery dQuery = new SPQuery();
dQuery.ViewAttributes = "Scope=\"Recursive\"";
string QueryString = "<Where>" +
"<Eq>" +
"<FieldRef Name=\"FileLeafRef\"/>" +
"<Value Type=\"Text\">" + fileName + "</Value>" +
"</Eq>" +
"</Where>";
dQuery.Query = QueryString;
SPListItemCollection collListItems = list.GetItems(dQuery);
return collListItems;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.