1

I don't want to show the file name for a document in a document library to my users who can only view the documents. Instead I want to show them the friendly Title. My challenge is that if I don't show the file name, there appears to be no column available the user can click to view the document.

Is there a way to accomplish this? Maybe make the Title be a link that opens the document or have the document type icon be a link to open the document?

I am using SharePoint Foundation 2013 in a hosted environment and thus cannot install any wsp files into SharePoint. Any assistance would be greatly appreciated.

  • Why not have the file name be the same as the friendly Title. Why does it have to be different? – JacobCaldwell Aug 1 '17 at 19:56
  • Because file names are used to find a file on a disk. titles are what the document are. For example, a document title might be Meeting Minutes however the file name might be Meeting_Minutes_2017-07-31.docx. – George M Ceaser Jr Aug 1 '17 at 20:31
2

You can use the JS Link.

Add the following script to the JS file

(function () {

    var docsCtx = {};
    docsCtx.Templates = {};

    docsCtx.Templates.Fields = {
        'Title': {'View': titleFieldTemplate}     
    };

    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(docsCtx);

})();

function titleFieldTemplate(ctx) {
    var url = ctx.CurrentItem.FileRef;
    var title = ctx.CurrentItem.Title;

    return '<a href="' + url + '">' + title + '</a>';
}

Refer the file path to the List View Web part JSLink property under Miscellaneous section.

It will display as below

enter image description here

  • What JS file are you talking about? I am using SharePoint Foundation 2013. – George M Ceaser Jr Aug 1 '17 at 20:51
  • You can add a custom JS file with above script to the Site Assets library. – Venkat Konjeti Aug 1 '17 at 20:55
  • OK so add my own JS file with this script point to that file in the Misc section of the webpart properties. I will try it. Thanks – George M Ceaser Jr Aug 1 '17 at 21:37
  • Yes. Let me know if you stuck any point of time. – Venkat Konjeti Aug 1 '17 at 21:41
  • So is what you have above EXCECTLY what I need to put in the JS file? no <script tags etc?? I ask because when I put just what you have above and added a reference in the webpart misc section on my SharePoint foundation 2013 site, my site went all flakey. The page with the webpart I added the js file to would not show any content only the webpart header and all the Edit features at the top of the site were gone (i.e. no Ribbon, no options in the top right corner for Site Settings etc.) – George M Ceaser Jr Aug 2 '17 at 0:01

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.