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…
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.
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
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!
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
It isn’t the worst thing ever – it’s API just has a lot of kinks in it.
In terms of knowing the site, this should be implicit in the Site that you’re using the _vti_bin for, as defined in the URL. e.g.
http://sharepoint.example.com/Somesite/SiteImQuerying/_vti_bin
would have the context for the SiteImQuerying site.
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 🙂