locked
Sharepoint 2013 IsContentTypeAllowed always true RRS feed

  • Question

  • Hi, all!

    In Sharepoint 2010 this expression return  only SPList where ContentTypeId is exist. 

    In Sharepoint 2013 it returns always true for any lists.

    var listItems=web.Lists.OfType<SPList>().Where(
                        list =>
                            list.IsContentTypeAllowed(OrderOfBusinessCardsContentTypeId.OrderOfBusinessCard)).ToList<>();

    Why is this happening?

    Best regards




    • Edited by Ms Anka Tuesday, June 3, 2014 1:20 PM
    Tuesday, June 3, 2014 1:16 PM

Answers

  • Hi,

    According to your post, my understanding is that the IsContentTypeAllowed always displayed true.

    I had used the following code snippets to check whether the IsContentTypeAllowed displayed true.

    When I used the “Document” content type, it returned the false.

    using (SPSite site = new SPSite("http://sp"))
    
                {
    
                    using (SPWeb web = site.OpenWeb())
    
                    {
    
                        SPContentType contentType=web.AvailableContentTypes["Document"];
    
    
                        if (contentType!=null)
    
                        {
    
                            SPList list = web.Lists["list1"];
    
                            list.ContentTypesEnabled = true;
    
                           // bool flag=IsContentTypeAllowed(list,contentType.Id);
    
                            if (!list.IsContentTypeAllowed(contentType))
    
                            {
    
                                Console.WriteLine("The {0} content type is not allowed on the {1} list",
    
                                contentType.Name, list.Title);                       
    
                            }
    
    
                            else
    
                            {
    
                                Console.WriteLine("The contenty type is allowed");
    
                            }
    
                        }
    
                        else
    
                        {
    
                            Console.WriteLine("The content type not exist..");
    
                        }
    
                    }
    
                }
    

    You can also use the below code to check whether your content type ID is equal to the built in content type ID while debugging.

    YourContentType.Id.IsChildOf(SPBuiltInContentTypeId.Document);

    Thanks,
    Jason
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.



    Jason Guo
    TechNet Community Support

    • Proposed as answer by sk2014 Friday, June 6, 2014 12:55 PM
    • Marked as answer by Lindali Sunday, June 15, 2014 7:51 AM
    Friday, June 6, 2014 7:59 AM