0

I am trying to create a URL/ Link with current item attachment filename.

My example

  • List name: MyList
  • ItemID : 100
  • LinkField: NULL
  • attachments: abc.csv & abv.doc

I would like create a string like : MyItem=100&Myattachment=abc.csv and save into a field (LinkField)

I can use javascript, REST, XSL, or anything to make it work.

  • I don't need something like this: <xsl:element name="SharePoint:AttachmentsField"> <xsl:attribute name="runat">server</xsl:attribute> <xsl:attribute name="ListId">{D2C70ED5-8551-446D-B0CF-AC4B30387CF0}</xsl:attribute> <xsl:attribute name="FieldName">Attachments</xsl:attribute> <xsl:attribute name="ControlMode">Display</xsl:attribute> <xsl:attribute name="Visible">true</xsl:attribute> <xsl:attribute name="ItemId"> <xsl:value-of select="@ID"/> </xsl:attribute> </xsl:element> – JW120 Aug 19 '15 at 22:59
  • If you can just display in the aspx page, it might work for me. Display it as html code: <a href="Mysite/…>.... <a href="Mysite/…>.... – JW120 Aug 19 '15 at 23:01
  • In Sharepoint 2013 – JW120 Aug 19 '15 at 23:15
  • Thank you so much for everyone! Finally, I can make it work. – JW120 Aug 29 '15 at 6:12
0

If I understand you correctly you just need a column that contains a link to each attachment that that item has.

An easy way is to do it via jquery and then attach it to the list.

Answer taken from here:https://social.technet.microsoft.com/Forums/en-US/74dac191-5a9e-4970-a9f6-a501846f0bef/forum-faq-show-attachments-in-sharepoint-2013-custom-list-view?forum=sharepointgeneral

See code below:

(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;

}

  • I have uploaded the js files and create a view for my list. But I cannot "edit page" it because it is the list view page. I can Edit List. So how can I put "~site/SiteAssets/jquery-1.11.1.min.js|~site/SiteAssets/showAttachments.js" into JSLink field? Do I need to create a blank new page and add the list web parts? – JW120 Aug 20 '15 at 16:11
  • I created a new page and added the list in the page. Then, put the "~site/SiteAssets/jquery-1.11.1.min.js|~site/SiteAssets/showAttachments.js" into JSLink field. But it return error like this: "'$' is undefinedTypeError: Unable to get value of the property '_events': object is null or undefined" – JW120 Aug 20 '15 at 16:21
  • If I remove "|~site/SiteAssets/showAttachments.js", the page is working fine. – JW120 Aug 20 '15 at 16:24
  • I would assume that the link you are using is wrong. Is the url for the .js correct? (Currently don't have the time to test this although I have used it before so it should work somehow) – Roland Aug 21 '15 at 1:35
  • 1
    <script type="text\javascript" src="code.jquery.com/jquery-1.11.3.min.js"> This is the issue. "\" vs "/" – JW120 Sep 1 '15 at 15:15

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.