How to Set Default content type in document set in SharePoint

Source: Internet
Author: User

I had encounter a issue when set default content type in document set, had to work around it

Create a custom document set in library, besides I want the document set only contains a content type I want to use, hence add a custom content type in the document set, and remove the default "en" T type. finally, there will be only one content type, but, when upload document in the document set, it is not working, it still had the content type named "document ", even it is the default content type, it is a bug in Sharepoint, that is not my expected. I have to work around it.

This is default content type in Sharepoint,

But what I expected is it:

 

1. Here is my thinking:

1. observe that the href is alway changing when switch the content type in uploading, the only changed is the content type ID in URL, so we just update the content type ID and navigate the new locatio href, it will be working.

2. Besides, I found that the URL had no content type ID in the first open uploading dialog, so we just apppend the content tyepe ID after the URL when open the uploading dialog.

2. Here is my steps

1. create a document library named "knowledgelibrary", and create some document sets, at this time, each of the document set has the only and correspond content type (for example: documentseta, documentsetb, contenttypea, contenttypeb, And the ID of default document content type)

2. Add script Web Part in editform of knowledgelibrart

<script>$(function(){    var locationUrl = location.href;    var rootFolder = "";    var contentTypeId = "";    rootFolder = locationUrl.substring(locationUrl.indexOf("RootFolder"),locationUrl.length);    rootFolder = rootFolder.substring(0 ,rootFolder.indexOf("&"));    contentTypeId = locationUrl.substring(locationUrl.indexOf("ContentTypeId"),locationUrl.length);    contentTypeId = contentTypeId.substring(0 ,contentTypeId.indexOf("&"));    if(locationUrl.indexOf("ContentTypeId") < 1){rootFolder = rootFolder.substring(rootFolder.indexOf("KnowledgeLibrary%2F")+19);if(rootFolder.indexOf("%2F")>0){rootFolder = rootFolder.substring(0, rootFolder.indexOf("%2F"));}        // document content type id for default content typevar contentDefaultID= "0x010100579C194BB641F9459CFD192AF39DC1FE";        console.log("rootFoldr :" + rootFolder);        switch(rootFolder){        case "DocumentSetA" :             contentDefaultID=  ContentTypeAId;            break;        case "DocumentSetB": contentDefaultID=  ContentTypeBId;                break;           default: contentDefaultID= "0x010100F3FA1C5131EDFB4A90F1E96FAF0F8B9F";                 break;}      location.href = locationUrl + "&ContentTypeId=" + contentDefaultID;      console.log(location.href);    }});</script>
3. Here is the result:

1. It is defalut document content type in begin loading

2. Javascript change the content type

How to Set Default content type in document set in SharePoint

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.