1

We've noticed an issue in our SharePoint 2013 document libraries. When uploading documents to a document set in a document library, content types available to the root document library are available in the document set, even if that same content type isn't available to the document set. This is particularly challenging as users aren't seeing their documents in document sets as they've been erroneously tagged as the wrong content type as is the case when users drap/drop items into document sets.

I'd like to try to modify the new document pop up to strip out these invalid content types. Is there a way to query the document set's properties to find valid content types?

Tks

1

modifying the UploadEx.aspx or Upload.aspx isn't a good idea as You will by modifying an application page under /layouts/15 which is shared for all libs across the farm. Maybe better approach would be to try to get all CT that are associated with this lib by PowerShell or CSOM and try to find the not valid ones and get their GUID. Then get all the items with this not valid CT and change it to a valid one. After that remove the not valid CT from list and change the default CT to some valid one. Here is some simple powershell to get all CT in list (this would be a good script to start if You will consider this approach)



    if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {
        Add-PSSnapin "Microsoft.SharePoint.PowerShell";
    }

    $_URL = "URL";
    $SPWeb = Get-SPWeb $_URL;

    $SPList = $SPWeb.Lists["LIST_NAME"];
    foreach($ct in $SPList.ContentTypes)
    {
        $ct.Name;
        $ct.Id;
    }

let me know if this was of any help :)

***** UPDATE *****

Since You want to modify the upload application page and I suggested attaching some javascript to it I would go with Rest Api to get CT for list and also the ones attached to Document Set. something like



    https://{SITE_URL}/_api/web/Lists/getbytitle('{LIST_NAME}')/items?$select=Title,ContentTypeId

should do the trick. so the request would look something like this



    $.ajax({
    url: "https://{SITE_URL}/_api/web/Lists/getbytitle('{LIST_NAME}')/items?$select=Title,ContentTypeId",
    type: "GET",
    cache: false,
    headers: {
        "accept": "application/json; odata=verbose",
        "content-type": "application/json;odata=verbose",
        "X-RequestDigest": $("#__REQUESTDIGEST").val()
    },
    success: function(data) {
        console.log(data.d.ContentTypes.results);
    },
    error: function() {
    console.log("error");
       }});

Please be aware that the above code with request is not tested... but I think should work or some small changes will be needed :)

4
  • Thanks Adam. The document library has a few different content types, so I can't just apply a valid one using the approach mentioned above- the user uploading the file needs to do that. And I should have been more clear about my approach. When uploading documents, I want to display the new file popup and dynamically remove the invalid CT options. Is this possible by querying the CT available to the document set using CSOM (would have to be a client side script)? – Steven C Jun 25 '19 at 19:13
  • sure... basically if You manage the SharePoint farm You can make changes to the upload.aspx but this is not recommended. I the scenario You described the easiest approach would be to modify "Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\LAYOUTS\upload.aspx" add some kind of JS to it. In this JS check if the CT select filed contains <option> tags with those 'not valid' CT GUIDs and just remove them. a batter approach would be to create Your own application page added to mapped _layouts folder and for this document lib overwrite the ribbon custom action to open Your page – Adam Jun 26 '19 at 7:22
  • Thanks Adam. I don't suppose you have an example script I could use to query the docLib/document set to enumerate all CTs associated with it? – Steven C Jun 27 '19 at 17:43
  • sure :).. .please see my update.. I did my best.. today I don't have any SP environment to test it totally but I suppose should work :) ... I hope :) – Adam Jun 27 '19 at 19:41

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.