1

I have a document library with content type "Document Set". This is OOB.

I have created another custom content type called "For Document Set" and its parent content type is "Document"

Problem is when I upload files inside "Document Set" then it is showing me both "For Document Set" and "Document" content types in "Content Type" drop down menu. So basically a user can upload document in "Document Set" and associate it with either "Document" or "For Document Set"

I only want "For Document Set" to appear there.

I have deleted "Document" and added "For Document Set" inside "Document Set Settings" page but no luck. How to fix this issue?

EDIT

Ok I got what the problem is but I don't know its solution. The thing is, this document's library |Default Content Type" is set to "Document". That's why when I upload document in root, then it doesn't show any drop down menu and associate it with default content type. But when I upload document inside "Document Set" then it gives user the option to either associate it with "Document" or "For Document Set" content type.

Is there any way to change the default content type of a content type? Looks like this setting is only available for a document library.

1
  • Ok I got what the problem is but I don't know its solution. The thing is, this document's library |Default Content Type" is set to "Document". That's why when I upload document in root, then it doesn't show any drop down menu and associate it with default content type. But when I upload document inside "Document Set" then it gives user the option to either associate it with "Document" or "For Document Set" content type. Nov 18, 2014 at 12:51

1 Answer 1

0

I'm actually fixing the exact same issue right now, this is an issue with how SharePoint picks the default ContentType of a document when you upload it.

When you upload a document to a DocumentSet SharePoint sets the ListItem ContentType to whatever the default ContentType for the List, this happens even if that ContentType in not valid in your DocumentSet. you can check if it's not valid by trying to change ContentTypes in the Editform page, if you change ContentTypes the default invalid value will no longer be present in the ContentTypes drop down

A solution i came up with for this is to create an EventReciever that detects if a new ListItem in in a documentSet and validates that it's ContentTypeID exists in yourDocumentSet.ContentTypeTemplate.AllowedContentTypes, if it does not simply change the listItem's ContentTypeID to the first Availible valid ContentType.

An alternative solution that doesn't work for your specific problem but may work for others people is to set the default Document ContentType in a given list to one that will be valid for all DocumentSets in the list.

Edit: here's a code solution using an event receiver. we need to catch itemUpdated for file overwrites. All we do is see if the document is inside a documentSet and has an invalid contenttype, if so we change the content type to the first available one in the document set.

  public override void ItemAdded(SPItemEventProperties properties)
    {
        try
        {
            this.EventFiringEnabled = false;
            UpdateItemCT(properties);
        }
        finally
        {
            this.EventFiringEnabled = true;
        }
        base.ItemAdded(properties);
    }

    public override void ItemUpdated(SPItemEventProperties properties)
    {

        if (properties.AfterProperties["vti_contenttag"] != null) return;
        try
        {
            this.EventFiringEnabled = false;
            UpdateItemCT(properties);
        }
        finally
        {
            this.EventFiringEnabled = true;
        }
        base.ItemUpdated(properties);
    }

    public void UpdateItemCT(SPItemEventProperties properties)
    {
        DocumentSet documentSet = DocumentSet.GetDocumentSet(properties.ListItem.File.ParentFolder);
        if (documentSet != null)
        {
            if (documentSet.ContentTypeTemplate.AllowedContentTypes.Count > 0)
            {
                bool isValidCt = false;
                SPContentTypeId defaultId = SPContentTypeId.Empty;
                foreach (SPContentTypeId ctId in documentSet.ContentTypeTemplate.AllowedContentTypes)
                {
                    if (ctId == properties.ListItem.ContentTypeId)
                    {
                        isValidCt = true;
                        break;
                    }
                    if (defaultId == SPContentTypeId.Empty)
                    {
                        defaultId = ctId;
                    }
                }
                if (!isValidCt)
                {
                    properties.ListItem["ContentTypeId"] = defaultId;
                    properties.ListItem.SystemUpdate(false);
                }
            }
        }
    }
3
  • And you know what, if you go to "Document Set Settings" and remove "Document" from "Allowed Content Types" and only add "For Document Set", it still shows both of these when user uploads file. I don't know then what's the purpose of giving this "Allowed Content Types" option in Document Set Settings. Nov 19, 2014 at 6:24
  • Looks like this is a bug? sharepoint.stackexchange.com/questions/21986/… Nov 19, 2014 at 7:05
  • Yeah it's a bug, luckily this only happen on upload.
    – Gilgamesh
    Nov 20, 2014 at 11:43

Your Answer

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

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