SharePoint 2007 : Get all list items in a list regardless of view from web service?

一世执手 提交于 2020-01-15 09:44:09

问题


I need to check for duplicates. Currently I have items stored in sub folders in a list.

How can I retrieve all items in the list from a web service, so I can check for duplicates?

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);

        }

    }

}

回答1:


Use SPList.Items doesn't return all items? Well, then try SPList.GetItems(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

Note: There could be some mistakes in code, because i`m writing from top of my head

By executing this query and if it returns more than one item, then you have a duplicate!

Edit: Ahh, sorry, you are talking about Web Services.

Then this code won't help. There are 2 options then:

Option 1: You CAN create a view that does include items even from folders (flat view). See here for instructions.

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>

Good luck!




回答2:


You can use the Lists.asmx web service, but that is quite hard to do as it returns quite a lot of information. I would deploy a custom web service on my SharePoint environment that contains that code and returns the list items.



来源:https://stackoverflow.com/questions/1707623/sharepoint-2007-get-all-list-items-in-a-list-regardless-of-view-from-web-servi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!