[Forum FAQ] Show Attachments in SharePoint 2013 Custom List View

转载 2015年07月07日 18:00:51
  • Introduction:

    By default, there is an Attachments column in the SharePoint List, some people want to display attachments name and click name can open the documents in List View. In this article, we would show you the method with REST API, JSLink and jQuery.

    Solution:

    The steps in detail as follows:

    1.        Download the jQuery API  and upload the js file into the SiteAssets Document Library.
    2.        Save the following code as a js file (showAttachments.js) and upload it into the SiteAssets Document Library.
    (function () {
    
        // Create object that have the context information about the field that we want to change it output render  
    
        var attachmentsFiledContext = {};
    
        attachmentsFiledContext.Templates = {};
    
        attachmentsFiledContext.Templates.Fields = {
             
            "Attachments": { "View": AttachmentsFiledTemplate }
        };
    
        SPClientTemplates.TemplateManager.RegisterTemplateOverrides(attachmentsFiledContext);
    
    })();
    
    
    // This function provides the rendering logic for list view 
    function AttachmentsFiledTemplate(ctx) {
        var itemId = ctx.CurrentItem.ID;
        var listName = ctx.ListTitle;       
        return getAttachments(listName, itemId);
    }
    
    //get attachments field properties
    function getAttachments(listName,itemId) {
      
        var url = _spPageContextInfo.webAbsoluteUrl;
        var requestUri = url + "/_api/web/lists/getbytitle('" + listName + "')/items(" + itemId + ")/AttachmentFiles";
        var str = "";
        // execute AJAX request
        $.ajax({
            url: requestUri,
            type: "GET",
            headers: { "ACCEPT": "application/json;odata=verbose" },
            async: false,
            success: function (data) {
                for (var i = 0; i < data.d.results.length; i++) {
                    str += "<a href='" + data.d.results[i].ServerRelativeUrl + "'>" + data.d.results[i].FileName + "</a>";
                    if (i != data.d.results.length - 1) {
                        str += "<br/>";
                    }                
                }          
            },
            error: function (err) {
                //alert(err);
            }
        });
        return str;
    }


    3.     Edit the list view page.

    4.Edit the list web part. Go to Miscellaneous -> JS Link.

    5.    Add the following URL into the JS Link textbox.

    ~site/SiteAssets/jquery-1.11.1.min.js|~site/SiteAssets/showAttachments.js

    Result:<o:p></o:p>


    Please click to vote if the post helps you. This can be beneficial to other community members reading the thread.

相关文章推荐

SharePoint 2013 中使用客户化的 (Custom) Filter web part 过滤OOB list view

本文讲述如何在SharePoint 2013 中使用客户化的 (Custom) Filter web part 过滤OOB list view。...

Custom Ribbon in SharePoint 2010 & which not wrok when migrate from 2010 to 2013

Custom Ribbon in SharePoint 2010 & which not wrok when migrate from 2010 to 2013
  • FoxDave
  • FoxDave
  • 2014年05月13日 16:36
  • 1911

Custom Search Center in SharePoint 2013

A Search Center is a portal where you can search for content on your organization’s intranet. In thi...

Custom Outcome Options of Task Form in SharePoint Designer on SharePoint 2013 Workflow

本篇文章主要讲述怎么在 SharePoint 2013 Workflow 中个性化 Task Form中的Outcome 选项,在默认的情况下应该只会有 approved 、reject,为了满足对于...

Adding Custom Actions to the List Item Menu in SharePoint 2010 Using SharePoint Designer 2010[Sharepoint中添加自定义菜单]

http://www.endusersharepoint.com/2010/02/02/adding-custom-actions-to-the-list-item-menu-in-sharepoin...
  • SseJava
  • SseJava
  • 2011年01月18日 14:04
  • 1051

SharePoint 2013 list froms(new/update/view) 某个字段只对某个SharePoint组的成员可见

SharePoint 2013 list froms(new/update/view) 某个字段只对某个SharePoint组的成员可见

sharepoint 2016 学习系列篇(12)-自定义列表应用篇-(1)创建一个自定义列表(Create a custom list)

sharepoint平台,有很多特别实在又好用常用的功能之一,自定义列表(Custom list),我们可以用它,来创建很多列表数据应用,来存储数据,无需开发,就能在线,增加,修改,删除,查询等操作数...

How to redirect to a Custom Page for Event Receiver in SharePoint 2010

Introduction:An event receiver in SharePoint allows great flexibility to meet various user requireme...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:[Forum FAQ] Show Attachments in SharePoint 2013 Custom List View
举报原因:
原因补充:

(最多只允许输入30个字)