SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How to get a SPListCollection through a sharepoint 2010 web service? Is it possible?

I was trying like this:

using (SPSite osite = new SPSite(siteUrl))
    using (SPWeb oweb = osite.OpenWeb())
        SPListCollection lstCol = osite.OpenWeb().GetListsOfType(SPBaseType.DocumentLibrary);

        return lstCol;

So, is there any alternative way to achieve this?

share|improve this question
up vote 1 down vote accepted

You have to take the information from the SPList entries in the SPListCollection and put them into some serializable class to return from your web service.

The SPListCollection can't be serialized as it contains SPList objects which needs reference to their SPWeb and the unmanaged COM object behind this to get any information, this is also why you can't use a SPList after the corresponding SPWeb has been Disposed (at least not without leaking memory)

share|improve this answer
+1 and I would recommend checking out my question/answer here: – Kit Menke May 15 '12 at 21:23

Well in lists.asmx, there is the GetListCollection operation, is that what you're looking for?

share|improve this answer
What I'm trying is to create a custom web service that will return SPListCollection object.Actually,I don't want to get the data in xml format. – DeathRider May 15 '12 at 15:06
Then that probably doesn't help. You might want to rephrase your question a bit. – Eric Alexander May 15 '12 at 15:10

SPListCollection is a server side only object and should only be used there.

I would go down the REST path /_vti_bin/ListData.svc ( or take the CSOM path (

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.