0

I've added a couple of CT's to a list. I can create a item with a selected CT from the ribbon. However when I select new item from the link (located in the page) it always gives me the default CT.

I have seen this where the newform has a dropdown allowing the user to select the required CT. How is this possible?

1 Answer 1

0

If you look at the list item template (C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\CONTROLTEMPLATES\DefaultTemplates.ascx) you will find that the ChangeContentType control is used.

You need to create your own control, inherit it from ChangeContentType control and override visible property. After this you should create your own template and use it for your list.

public override bool Visible
{
  [SharePointPermission(SecurityAction.Demand, ObjectModel = true)] get
  {
    if ((this.ControlMode == SPControlMode.Display) || this.List == null || (!this.List.ContentTypesEnabled || !base.Visible))
      return false;
    int num = 0;
    foreach (SPContentType spContentType in (IEnumerable<SPContentType>) this.ItemContext.ContentTypes)
    {
      if (this.ItemContext.FormContext.IsFolder || !spContentType.Id.IsChildOf(SPBuiltInContentTypeId.Folder))
        ++num;
    }
    return num > 1;
  }
  [SharePointPermission(SecurityAction.Demand, ObjectModel = true)] set
  {
    base.Visible = value;
  }
}
2
  • Hi I had a suspicion it was server side code :) should the above code be added to a VS feature? if could you please tell me how to do that. Thanks Commented Oct 21, 2014 at 12:24
  • You need to create SharePoint farm solution, add a user control and inherit it from ChangeContentType class, override visible property, add a safe control entry. Then add to this solution controltemplates mapped folder and copy list template from the DefaultTemplates.ascx, change ChangeContentType control to your control. The last, add your content types to the solution and register your list template in these content types.
    – Alexander
    Commented Oct 21, 2014 at 13:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.