Question

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.

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top