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

I am trying to know if a content type is hidden (Visible not checked in Change new button order and default content type section) on a SharePoint list using SharePoint web services. I have tried the GetListContentTypes() and GetListContentType() methods in the Lists.asmx web service but the result does not include the Hidden attribute.

How can i find if a content type is hidden using SharePoint web services without using the SharePoint API? Do I need to create a custom web service?

share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

Are you working with SharePoint 2007 or 2010? In 2010 you can use the new Client Object Model to get this information. When you do changes in the Change new button order and default content type you can see this information in the List.RootFolder.ContentTypeOrder collection. This collection only contains the visible ContentTypes, so you need to check it against all the ContentTypes on the list to find the hidden ones. See example for getting the ContentTypeOrder collection:

Add Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client.Runtime.dll as references to your project and try this code:

using (Microsoft.SharePoint.Client.ClientContext ctx = new Microsoft.SharePoint.Client.ClientContext("http://servername/"))
{
    var web = ctx.Web;
    ctx.Load(web);
    var query = ctx.LoadQuery(web.Lists.Where(p => p.Title == "Documents"));
    ctx.ExecuteQuery();

    List list = query.FirstOrDefault();
    ctx.Load(list.RootFolder, folder => folder.ContentTypeOrder);
    ctx.ExecuteQuery();

    foreach (ContentTypeId contentTypeId in list.RootFolder.ContentTypeOrder)
    {
        Console.WriteLine(contentTypeId.ToString());
    }
}
share|improve this answer
    
I have tried the SharePoint client object model on the list level and got the content types. But the problem is that the "Hidden" attribute of all content types is false even if I unchecked them in the “Change new button order and default content type” section. Do you have any idea? –  user3470 Jan 9 '12 at 7:38
    
It seems that it can’t be done using the SharePoint web services. I can create my own web service or use the SharePoint client object model as you described. –  user3470 Jul 10 '12 at 6:38
add comment

Can you try using Webs.asmx and use the Method GetContentTypes. The response xml would be as below

<ContentType Name="System" ID="0x" Description="" Group="_Hidden" NewDocumentControl="" Scope="http://metechmeydhango:5000" Version="0" RequireClientRenderingOnNew="TRUE" xmlns="http://schemas.microsoft.com/sharepoint/soap/" > 

From above response xml you can find the Group as Hidden

share|improve this answer
    
The “Group” attribute in this xml defines the group that the content type belongs to on the site level. If I created a custom content type and added it to the “Custom content types” group, the “Group” attribute will be equal to “Custom content types”. So I can’t know if the content type is hidden on a specified list and visible on the other. –  user3470 Jan 9 '12 at 7:00
add comment

Your Answer

 
discard

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