Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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
add comment

3 Answers

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: stackoverflow.com/a/1400380/98933 –  Kit Menke May 15 '12 at 21:23
add comment

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

share|improve this answer
add comment

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)

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. –  PirateEric May 15 '12 at 15:10
add comment

Your Answer

 
discard

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.