views:

489

answers:

2

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

        }

    }

}
+2  A: 

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!

Janis Veinbergs
I used your code and created a custom web service - what a royal pain in the keyster
JL
+1  A: 

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.

KoenVosters