3

On our SP 2013 discussion board, if the user wants to insert a file, they click in the body of the new discussion and then on "Upload File" in the ribbon.

When the "Add a document" dialog window opens up, the default "destination library" is always set to "Images".

How do i change this to a different default library? Our users are always inserting documents, not images.

enter image description here

4

There is an easier way to accomplish changing the default destination folder. Just go to 'advanced settings' in the library. There you can say if you want this library to be the default one for site activa. Check 'yes' en check 'no' in the advanced settings of every other library on the site. Done!

  • Thanks. That does the trick to change the default destination library. – C. Poulain Mar 3 '16 at 17:04
  • 1
    One thing i'm still wondering about. By default Sharepoint has a number of libraries with the "Site Assets Library" checkbox checked. (site assets, site collection images, etc) How does Sharepoint choose which library to display as the default in the drop-down list when there are multiple to choose from? – C. Poulain Mar 3 '16 at 17:10
2

Ok,..I have figured it out and am shocked at the work i had to do to change the default upload library.

I had to replace the "upload" button on the ribbon with my own, create a new upload dialog window and then process the filename returned so that i could insert a link to the file in the discussion post.

I feel like there has to be an easier way and will knock my head on the wall if i eventually find a setting in SP to accomplish this.

Regardless, here is the script that i had to insert to on the page,..

<script language="javascript" src="path_to_jquery_file/jquery2.1.0.js"></script>

<script language="javascript">

//for removing the load detecting

var hideRibbonTimeout = 0;

var newButtonPresent = false;


//check to see if this the discussion board we want to trim

if (jQuery('#s4-titlerow a:contains(Forum)').length > 0) {

   setTimeout(HideRibbonButton, 10);

}

//replace the current "Upload File" button to override the SharePoint button

function HideRibbonButton() {

   $('a[id*="UploadFile-Large"]').replaceWith('<a class="ms-cui-ctl-large newDialog" id="btnUpload" aria-describedby="Ribbon.EditingTools.CPInsert.Links.UploadFile_ToolTip" mscui:controltype="Button" role="button" id="Ribbon.EditingTools.CPInsert.Links.UploadFile-Large"><span unselectable="on" class="ms-cui-ctl-largeIconContainer"><span unselectable="on" class=" ms-cui-img-32by32 ms-cui-img-cont-float"><img unselectable="on" alt="" src="/_layouts/1033/images/formatmap32x32.png" style="top:-224px; left: -64px;"></span></span><span unselectable="on" class="ms-cui-ctl-largelabel">Upload<br>File</span></a>');

if (jQuery('.newDialog').length> 0) {

          newButtonPresent = true;


   }

   hideRibbonTimeout++;

   if (hideRibbonTimeout < 1000) {

          if (newButtonPresent == false) {

                 setTimeout(HideRibbonButton, 10);

          }

   }

}

//handle the "Upload File" click and create our own upload dialog box
// The returnValue from the upload form must be processed to create the hyperlink that will be inserted into to the discussion post

$(document).on('click', '#btnUpload', function () {

   newButtonPresent = true;

   SP.UI.ModalDialog.showModalDialog({

          url: L_Menu_BaseUrl + "/_layouts/upload.aspx",


          title: "Upload a file",

          dialogReturnValueCallback: function (result, returnValue) {

                 if (result == SP.UI.DialogResult.OK) {

                    // Get the file path and extradt the filename from it.
        var fileURL = returnValue.newFileUrl;
        var filenameArray = fileURL.split("/");
        var filenamePosition = filenameArray.length;
        var theFileName = filenameArray[filenamePosition-1];

        // Display an icon before the file link. Start with default paperclip and check for a few common types

        // use some regular expression goodness to match the appropriate file extension
        var pattern=/\.[0-9a-z]+$/i;
        // extract file extension 
        var ext = (theFileName).match(pattern);
        ext = ext[0].toLowerCase();

        // set default icon
        var icon = '/_layouts/15/images/ATTACH16.PNG';  
        // check for excel
        if ( '.xls' == ext || '.xlsx' == ext){
            icon = '/_layouts/15/images/ICXLS.PNG';
        }
        // check for ms document
        else if( '.docx' == ext || '.doc' == ext){
             icon = '/_layouts/15/images/icdocx.png';
        }
        // check for powerpoint
        else if( '.ppt' == ext || '.pptx' == ext){
             icon = '/_layouts/15/images/PPT16.GIF';
        }
        // create the html to dipslay the file icon
        var thumbnail = '<img class="ms-asset-icon" src="'+icon+'">';

        // Create the clickable hyperlink to the file attachment
        var FileLink = "<a href=\"" + fileURL + "\">" + thumbnail + " " + theFileName + "</a>";

         //adds the link to the body of the discussion post  
        $('.ms-rtestate-write').append(FileLink);


                 }

          }

   });

   setTimeout(function () {          

   //finds the upload choice dialog box and set the documents library as the default

          var dlg = SP.UI.ModalDialog.get_childDialog();

          if (dlg != null) {

                 var dlgWin = $("html", window.parent.document);

                 //get the iframe with the select box

                 var dlgCont = $(dlgWin).find("#dialogTitleSpan:contains('Upload a file')").parent().parent().parent().find('iframe');



                 //Set Documents as the default library.  
        // The value corresponds to the selection you want marked as default.


        $(dlgCont).contents().find("#ctl00_PlaceHolderMain_SelectListSection_ctl01_AvailableDocLibs").val('790862b8-b364-4b6d-9ef9-6481f7508ac0');


          }

   }, 1000);

});

</script>
  • 1
    Thanks for returning and sharing your code. This was helpful for me trying to solve a similar problem. – Submits Apr 21 '16 at 15:09
0

If you go to your document library, advanced settings, and set 'Should this document library be the default site assets library for this site' to Yes, the library will be put at the top of the list.

0

A guy named Aaren liu answered this question. This steps solved for me also.

Go to the library showing as default for Full control > library settings > Advanced settings > disable “Should this document library be a site assets library”. Also make sure no other libraries enable this option.

Click here for more details

0

This post has focused on the upload form itself very closely. This form can be arrived at by the user under a couple of contexts depending on what form a user is uploading into/from which is why I attacked this problem from a differen perspective...

In the following context, I solved the setting of the target upload document library with a bit of jQuery scripting which I have demonstrated below.

This works for the scenario where a user has focused a rich text field in a "Add New Item" dialog window, which causes the "Insert" ribbon to appear. Following the users clicks to the upload button, jQuery extracts the select item from the hierarchy of iframes and sets the default library based on the value you want. Following the upload the link to the newly uploaded file is placed into the rich text field. (SharePoint 2013)

I have not tested this method in any other scenarios. I'm kind of new-ish to crafting jQuery client-side javascript so this probably can be written without nesting but it works!

    <script language="javascript" src="[YOUR JQUERY SRC]"></script>

    <script language="javascript">

    $(window).load(function () { 
    var interval = 400
        //console.log('Javascript Loaded');  // log the tracking of user clicks to debug input timing based on speed of site
        $("[#SELECTOR FOR RICH TEXT FIELD]").on('click', function () {
            console.log('Body Clicked!');
            setTimeout(function() {
                //console.log('Timeout 1 Fired.'); // log the tracking of user clicks to debug input timing based on speed of site
                $("[#SELECTOR FOR INSERT RIBBON TAB]").attr('onClick', 'return true'); // must set attr of onClick to return true to allow jQuery .on('click') to fire
                $("[#SELECTOR FOR INSERT RIBBON TAB]").on('click', function () {
                    //console.log('Insert Clicked!'); // log the tracking of user clicks to debug input timing based on speed of site
                    setTimeout(function() {
                        //console.log('Timeout 2 Fired.');
                        $("[#SELECTOR FOR UPLOAD BUTTON]").attr('onClick', 'return true');
                        $("[#SELECTOR FOR UPLOAD BUTTON]").on('click', function () {
                            //console.log('Upload Clicked!'); // log the tracking of user clicks to debug input timing based on speed of site
                            setTimeout(function() {
                                var pdoc = parent.document
                                $(pdoc).find("iframe").each(function() {
                                    $(this).contents().find("select").each(function() {
                                        if (this.name == "ctl00$PlaceHolderMain$SelectListSection$ctl01$AvailableDocLibs") { // this selector should be generic, you'll have to confirm this.
                                            $(this).val("[HEX/GUID]"); // find the guid value corresponding to your library choice in the selector.
                                        };
                                    });
                                });
                            },interval * 2);
                        });
                    },interval);
                });
            },interval);
        });
    });

    </script>

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.