1

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?

3 Answers 3

1

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)

1
1

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

http://msdn.microsoft.com/en-us/library/lists.lists.getlistcollection(v=office.12)

2
  • 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
    Commented May 15, 2012 at 15:06
  • Then that probably doesn't help. You might want to rephrase your question a bit. Commented May 15, 2012 at 15:10
1

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

I would go down the REST path /_vti_bin/ListData.svc (http://msdn.microsoft.com/en-us/library/ff521587.aspx) or take the CSOM path (http://msdn.microsoft.com/en-us/library/ee538683).

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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