SharePoint 2007:获取列表中的所有列表项,而不管Web服务中的视图如何? [英] SharePoint 2007 : Get all list items in a list regardless of view from web service?
问题描述
我需要检查重复项.目前,我的项目存储在列表的子文件夹中.
I need to check for duplicates. Currently I have items stored in sub folders in a list.
如何从Web服务检索列表中的所有项目,以便检查重复项?
How can I retrieve all items in the list from a web service, so I can check for duplicates?
这是来自对象模型的代码:我想做到这一点,但是要通过Web服务
Here is code from object model: I want to do exactly this, but from a web service
private static void PrintItemTitles()
{
string strUrl = "http://localhost:8099/";
using (SPSite site = new SPSite(strUrl))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists["MyList"];
SPListItemCollection items = list.Items;
foreach (SPListItem item in items)
if (item != null)
Console.WriteLine(item.Title);
}
}
}
推荐答案
使用SPList.Items不会返回所有项目吗?好吧,然后尝试 SPList.GetItems(SPQuery).
Use SPList.Items doesn't return all items? Well, then try SPList.GetItems(SPQuery).
具有以下SPQuery:
Have a following SPQuery:
SPQuery query = new SPQuery();
query.ViewFields = "<FieldRef Name='ID'/><FieldRef Name='Title'/>";
query.Query = String.Format("<Where><Eq><FieldRef Name='Title'/><Value Type='Text'>{0}</Value></Eq></Where>", someItemTitle)
query.MeetingInstanceId = -1; //In case if you query recurring meeting workspace - get items from all meetings
query.RowLimit = 10; //Will you have more than 10 duplicates? Increase this value
query.ViewAttributes = "Scope='RecursiveAll'"; //Also return items from folders subfolders
注意:代码中可能存在一些错误,因为我是从头开始写的
通过执行此查询,如果它返回多个项目,则表示您有重复项!
By executing this query and if it returns more than one item, then you have a duplicate!
然后此代码将无济于事.然后有2个选项:
Then this code won't help. There are 2 options then:
选项1:您可以创建一个视图 甚至包括文件夹中的项目 (平面视图). 在此处查看 说明.
Option 1: You CAN create a view that does include items even from folders (flat view). See here for instructions.
选项2:根据列表Web服务的 GetListItems 方法,可以传递QueryOptions参数.传递
Option 2: According to Lists Web Service's GetListItems method, you can pass QueryOptions parameter. Pass in
<QueryOptions>
<MeetingInstanceID>-1</MeetingInstanceID> <!-- Again, if you query recurring meeting, you want ALL items -->
<ViewAttributes Scope='RecursiveAll' /> <!-- or Recursive if that does not work -->
</QueryOptions>
祝你好运!
这篇关于SharePoint 2007:获取列表中的所有列表项,而不管Web服务中的视图如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!