While creating List with content type using CSOM why do we get "Post category does not exist" error?

Mansur Patel 0 Reputation points
2024-05-14T08:25:00.7+00:00

I am trying to create List with content type using CSOM. But I ma getting "Post category does not exist" error in response.

PostCategory is internal name for Category Field which appears when we try to add new item to the list of Custom type and that field is not showing any value.

Steps to reproduce:

1.Create List in the site.

2.Create 'Custom Type' of Type 'List'

3.In List advance setting set allow management of Custom type =true.

  1. Try adding new item to list of custom type.
  2. Category field does not show any value.
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,975 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
3,136 questions
{count} votes

2 answers

Sort by: Most helpful
  1. RaytheonXie_MSFT 36,896 Reputation points Microsoft Vendor
    2024-05-15T02:53:53.5833333+00:00

    Hi @Mansur Patel,You could use following csom code to enable the content type first

    using (ClientContext clientContext = new ClientContext("http://MyServer/sites/MySiteCollection"))
    {
    // clientcontext.Web.Lists.GetById - This option also can be used to get the list using List GUID
    //This value is NOT List internal name
    List olist = clientcontext.Web.Lists.GetByTitle("New title");
    olist.ContentTypesEnabled = true;
    olist.Update();
    clientcontext.ExecuteQuery();
    }
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. Mansur Patel 0 Reputation points
    2024-05-15T06:08:21.7666667+00:00

    @RaytheonXie_MSFT Thank you for your reply.

    I have already set this property and it is not working. I have also tried removing Post Category from ClientContext. still I get same issue.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.