Skip to main content
Tweeted twitter.com/StackSharePoint/status/865214601658593281
added 36 characters in body
Source Link
John John
  • 1
  • 49
  • 258
  • 603

EDIT now based on @Gautam reply, i tried this JSLINK , and it worked :-

now i tried this JSLINK , and it worked :-

EDIT now based on @Gautam reply, i tried this JSLINK , and it worked :-

added 2156 characters in body
Source Link
John John
  • 1
  • 49
  • 258
  • 603

now i tried this JSLINK , and it worked :-

(function () {  

    (window.jQuery || document.write('<script src="//ajax.aspnetcdn.com/ajax/jquery/jquery-1.10.0.min.js"><\/script>')); 

    var linkFieldContext = {};

    linkFieldContext.Templates = {};

    linkFieldContext.Templates.Fields = {

        "Attachments": { "View": AttachmentsFieldTemplate }
    };

    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(linkFieldContext);

})();



function AttachmentsFieldTemplate(ctx) {
    var listItemId = ctx.CurrentItem.ID;
    var listName = ctx.ListTitle;       
    return getAttachments(listName, listItemId);
}

function getAttachments(listName,listItemId) {

    var url = _spPageContextInfo.webAbsoluteUrl;
    var webServiceUrl = url + "/_api/web/lists/getbytitle('" + listName + "')/items(" + listItemId + ")/AttachmentFiles";
    var attachHtml = "";

    $.ajax({
        url: webServiceUrl,
        type: "GET",
        headers: { "ACCEPT": "application/json;odata=verbose" },
        async: false,
        success: function (data) {
            for(var i = 0; i < data.d.results.length; i++) {
                attachHtml += "<a href='" + data.d.results[i].ServerRelativeUrl + "'>" + data.d.results[i].FileName + "</a>";
                if (i != data.d.results.length - 1) {
                    attachHtml += "<br/>";
                }                
            }          
        },
        error: function (error) {
            console.log(error);
        }
    });
    return attachHtml;
}

but the problem i am facing is that when i click on the list view i will get the following error for a couple of seconds, then the page will refresh automatically and show the attachments correctly:- enter image description here

so is there a way to overcome this temporary error message which is being displayed??

now i tried this JSLINK , and it worked :-

(function () {  

    (window.jQuery || document.write('<script src="//ajax.aspnetcdn.com/ajax/jquery/jquery-1.10.0.min.js"><\/script>')); 

    var linkFieldContext = {};

    linkFieldContext.Templates = {};

    linkFieldContext.Templates.Fields = {

        "Attachments": { "View": AttachmentsFieldTemplate }
    };

    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(linkFieldContext);

})();



function AttachmentsFieldTemplate(ctx) {
    var listItemId = ctx.CurrentItem.ID;
    var listName = ctx.ListTitle;       
    return getAttachments(listName, listItemId);
}

function getAttachments(listName,listItemId) {

    var url = _spPageContextInfo.webAbsoluteUrl;
    var webServiceUrl = url + "/_api/web/lists/getbytitle('" + listName + "')/items(" + listItemId + ")/AttachmentFiles";
    var attachHtml = "";

    $.ajax({
        url: webServiceUrl,
        type: "GET",
        headers: { "ACCEPT": "application/json;odata=verbose" },
        async: false,
        success: function (data) {
            for(var i = 0; i < data.d.results.length; i++) {
                attachHtml += "<a href='" + data.d.results[i].ServerRelativeUrl + "'>" + data.d.results[i].FileName + "</a>";
                if (i != data.d.results.length - 1) {
                    attachHtml += "<br/>";
                }                
            }          
        },
        error: function (error) {
            console.log(error);
        }
    });
    return attachHtml;
}

but the problem i am facing is that when i click on the list view i will get the following error for a couple of seconds, then the page will refresh automatically and show the attachments correctly:- enter image description here

so is there a way to overcome this temporary error message which is being displayed??

Source Link
John John
  • 1
  • 49
  • 258
  • 603

Is there a way to show the actual Attachment links inside the list view for my custom list

I have added a custom list inside my sharepoint 2013. and i chose to attach a file inside my list item from "Edit Tab">>"Attach File". but when i chose to display the "Attachment" field inside my list view , i will get the following symbol:-

enter image description here

instead of the actual attachment link/s?? so is there a way to fix this ?