I've found this page which explains how to add a ‘Create New Document’ link to a page :

<img alt="" src="/_layouts/images/rect.gif">&nbsp;
<a onclick="createNewDocumentWithProgID('http:\u002f\u002fvm-moss2007\u002fMod Props\u002fForms\u002fMod Props\u002fModPropTemplate.xlsx', 'http:\u002f\u002fvm-moss2007\u002fMod Props', 'SharePoint.OpenDocuments', false);return false;" href="#">Create new Mod Prop</a>

My question is if it's also possible to add a link to a web-page which goes directly to the 'Add Document Set' functionality.


Go to this link and check answer from tuddy86

Mod edit, copying content over so it isn't lost.

This is how I managed to have a link to new document set form, thx!

This is the script I needed to make it happen from javascript:

<script type="text/javascript">

        var list;
        var listRootFolder;
        ExecuteOrDelayUntilScriptLoaded(init, "sp.js");

        function init() {

            //load site
            var currentcontext = new SP.ClientContext.get_current();
            list = currentcontext.get_web().get_lists().getByTitle('Contracts');

            currentcontext.load(list, 'Id', 'ContentTypes');
            currentcontext.executeQueryAsync(Function.createDelegate(this, result), Function.createDelegate(this, oncListQueryFailed));

        function result() {
            var listId = list.get_id();
            var relativeURL = _spPageContextInfo.webServerRelativeUrl;

            var url = relativeURL + "/_layouts/15/NewDocSet.aspx?List=" +
                + "&RootFolder=" + customEncode(relativeURL + "/contracts")
                + "&ContentTypeId=" + getContractContentTypeId(list);
            $("a#myLink").attr("href", url);

        function oncListQueryFailed(sender, args) {
            alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());

        function getContractContentTypeId(list) {
            var ct_enumerator = list.get_contentTypes().getEnumerator();
            while (ct_enumerator.moveNext()) {
                var ct = ct_enumerator.get_current();

                var ctypeId = ct.get_id().toString();
                if (ctypeId.startsWith("0x0120D52000F5F4E351EDB84EE992DB1245916364BC")) {
                    return ctypeId;

        function customEncode(url) {
            url = encodeURIComponent(url);
            url = url.replace('.', '%2E');
            url = url.replace(/-/g, '%2D');
            return url;


I had a custom document set content type in my scenario...

| improve this answer | |
  • 1
    I am afraid one liner or just link answers do not add any value. Would you please add some content or breif description on how to solve the problem. It will be helpful to other readers. – Asad Refai Jul 22 '15 at 11:03

I've tried a mixture of things and came across the following solution. I tried a solution to copy the URL for creating a new document set, but the link always led to a 'something went wrong' page.

The solution is based on https://jennyssharepointtips.wordpress.com/2014/07/30/launch-document-content-type-templates-from-any-web-page-with-a-link/

General steps after the doc set content type is created:

  • Modify the Doc Set view to "Show toolbar"
  • Search the page source for 'Create a new x' where x = name of document set item. For example "Create a new document set". Find the one located under the 'ms-toolbar' class and examine the block.
  • Copy the (long) code after onMenuClick, looks like "javascript:NewItem2(event, &#39;\u002fsites\yoursite\u002fsubsite\..." and ends with a content type ID
  • (Optional) Decode the \u002f with / and the &#39; with '
  • Create a CEWP / script editor webpart with hyperlink using the 'onclick' event <a onclick="javascript:NewItem2(event, '/sites/yoursite/yoursubsite/...">Create new document set</a>
  • Set the view toolbar to 'no toolbar'
  • (Optional) Change advanced settings on list to 'open in dialog'

Haven't sorted out how to edit the new docset aspx, but this was good enough for now.

| improve this answer | |

The code below will allow you to perform a redirect to a given page when the user clicks on New Item

$("a[id$='NewMenu']").click(function(e) { window.location = '/_layouts/smartaudit/UploadAudit.aspx'; return false; });
| improve this answer | |
  • Would you care to put some more context around that? How would you integrate that into the html snipped in the question? Where does the Document Set come in? – teylyn Jul 21 '13 at 23:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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