The circular logic of the WSS Lists Webservice GetListContentTypes call

So, I need to get a list of the content types applied to a library. The Lists webservice has a call for this:

<getlistcontenttypes xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<listname>string</listname>
<contenttypeid>string</contenttypeid>
</getlistcontenttypes>

So, I’m connected to a site, I supply a list name to identify the list… …but what do I give as a contentTypeId? I don’t have a f$%king clue – I was calling this function to try to find out what content types were valid!

Well, good news. It doesn’t seem to matter what you put in, you always get a list of all the content types on the list. I used the following code…

WS_Lists.Lists lsts = new WS_TestApp.WS_Lists.Lists();
lsts.Credentials = System.Net.CredentialCache.DefaultCredentials;
XmlNode node = lsts.GetListContentTypes(libraryName, contentTypeID);

I figured that maybe they wanted the base content type for what I wanted back, so I tried setting contentTypeID to documents (0x0101) and got back a list of all the content types. I then set contentTypeID to “fish”, and still got back a list of all the content types. As far as I can tell, the second parameter doesn’t do anything.

Side note: The first content type returned is your default content type.

Side note 2: There doesn’t seem to be an easy way of identifying non-visible content types…

Advertisement
The circular logic of the WSS Lists Webservice GetListContentTypes call

6 thoughts on “The circular logic of the WSS Lists Webservice GetListContentTypes call

  1. I discovered a similar thing with another product (which shall remain nameless) last week – while piecing together their database to do my own call to it for a function that doesn’t exist in their API, I saw a field and thought “that’s it – that will do what I want”.

    I then discovered that the field in question is always left empty. It’s a hangover from an earlier version of the software, and it’s absence means there is a logical “hole” in the system.

  2. Drew says:

    Hi Andy,

    I’m a MOSS administrator…but not a developer…

    I want to run the code you’ve mentioned above, but have no idea how…

    Any pointers? Do I need to use Visual Studio? Any information you could offer would be helpful

  3. Hi Drew,

    Yes, I was running that code from Visual Studio 2005. I :

    – created a little ‘Console Application’ project
    – included a ‘Web reference’ to the lists.asmx web service in the _vti_bin of the site I was dealing with. This would be a URL like http://exampleServer/siteA/_vti_bin/lists.asmx. I called the reference WS_Lists.
    – Added the code you see above
    – finally, I actually output the xml in ‘node’ to a file.

    Hope that helps!

  4. sh$%point says:

    good point. i was wondering the same thing. now i’m wondering how the f$%k “listname” is supposed to be enough information to get a specific list. somehow this f$%ker’s going to need to know the site… oh well. if sharepoint was straightforward it wouldnt be the worst goddamn thing ever

  5. Thanks for this – I have used your “anything” suggestion in the second parameter in 2007, and just managed to also get it working in 2010 using the same technique.

    Thanks 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.