Update 28th of July, 2014: Script updated to version 2.3 (see the changelog)
End of January I adapted the script to open list item attachments with a simple click on the paperclip symbol, which Alexander Bautz from spjsblog.com wrote, to SharePoint 2013.
In the last couple of days I have made some further improvements to this script which I want to share with you.
Due to the fact that SharePoint now stores the item ID within the the TR-tag’s ‘iid‘ attribute, it is not longer required to put the ID column into the view. Therefore, it also not necessary anymore to use the ‘hideIdColumn‘ attribute. Just decide in the view configuration whether you want to see this column or not.
Additionally I changed the presentation of the attachments to a nice speech bubble styled overlay which looks much better than the simple box from the earlier version (imho).
In order to style the speech bubble to your needs, I introduced three new properties which are ‘colorFont’, ‘colorGradientStart’ and’colorGradientEnd’. It is not necessary to give the bubble a gradient. If you want it to have a uniform color just give ‘colorGradientStart‘ and ‘colorGradienEnd‘ the same value.
- colorFont: the font color inside the bubble, can be a HEX (e.g. ‘#000000’), RGB (e.g. ‘rgb(0,0,0)’) or Word value (e.g. ‘black’)
- colorGradientStart: start color of the gradient (top), must be an RGB value (e.g. ‘rgb(231, 14, 30)’)
- colorGradientEnd: end color of the gradient (bottom), must be an RGB value (e.g. ‘rgb(187, 6, 20)’)
You can read about the other properties here.
The complete code snippet you have to put on the page may now look like that:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"> </script><script type="text/javascript" src="/Path to the Script/ListAttachments_v2.3.js"></script> <script type="text/javascript"> var argObj = {clickToOpen:false, clickMouseover:'Click to open', oneClickOpenIfSingle:false, colorGradientStart: 'rgb(231, 14, 30)', colorGradientEnd: 'rgb(187, 6, 20)', colorFont: 'white' }; </script>
In the example above, the bubble containing the links to the attachments will open when you hover your mouse over the paperclip symbol and will close when your mouse leaves the bubble. The color of the bubble is a gradient of two variations of red and the font color is white.
And here is how it looks like in action:
Enjoy the easy way to view and open list item attachments!
Update February 14th, 2014:
I made further improvements and the script will also show attachments in the Quick Edit mode, now:
Update July 28th, 2014:
Script now works with the Newsletter view style, too.
The ID column must be included in the view, otherwise it won’t work.
To hide the ID column use the argument ‘hideIdColumn’ with the value of ‘true’.
Example:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"> </script><script type="text/javascript" src="/Path to the Script/ListAttachments_v2.3.js"></script> <script type="text/javascript"> var argObj = {clickToOpen:false, clickMouseover:'Click to open', oneClickOpenIfSingle:false, colorGradientStart: 'rgb(231, 14, 30)', colorGradientEnd: 'rgb(187, 6, 20)', colorFont: 'white', hideIdColumn: true }; </script>
Hi. I am trying this work of yours in my List but sad to say it is not working. Can you guide me please? I am kinda lost.
What i did was make a standard view and add the title, id and attachment column. Then edit the view and add Script Editor and put it at the end of the page. But it did not work. Please help.
It’s really hard to tell why it is not working without further information.
However, I updated the script and maybe this version (v2.2) works better for you. According to what you did it should definitely work. I just tried it in my uncustomized SharePoint environment and it worked right from the start.
If v2.2 is not working as well, please have a look into the error console in your browser (F12) and tell me the error messages (if any).
Hi Daniel,
It worked. Than you so much. :))
Hi Daniel,
Me again. I would like to disable right click on the attachment to prevent it to be downloaded, is it possible?
Sure,
add the following code after line 212:
$(“div[id^=customAttDiv] a”).bind(“contextmenu”,function(){
return false;
});”
Hi there,
How did you get this working for you as it doesn't work for me at all?
I put the code in a CEWP but nothing happens??? No error anywhere…
I'm using ListAttachments_2.4.js
its not working with google Chrome and Mozilla.
Can you suggest any code changes required.
Thanks
Hi Subbu,
what exactly is not working? Any error messages?
Daniel
Hi Daniel – this is not working for me and it may be because I am using SharePoint Online (Office365) or because I am trying to get it to work in a View as opposed to in a web part.
The error that I get on the main page is “Web Part Error: Unknown server tag. Correlation ID: ce4d869c-93b8-b056-feb5-92fbae95bdf5.”
I also checked the F12 and the Console only had the following Informational entry “JavaScript Console is attached and accepting commands.”
Any ideas on what I can do from here?
Thanks, Mark
Hi Mark,
sorry for the late reply. I don’t completely understand what you did to get this result.
Were you able to follow all the steps that I mention in my post?
Hi Daniel… Cool widget, but we’re seeing a problem. In SharePoint 2013, when the code snippet is installed on the listview page, the tabs at the top of the page for items and list disappear. The only tab that remains is the Browse tab. We have to a use the HTTP:\\MYSHAREPOINT?ToolPaneView=2&pagemode=edit trick to get back into editing the page. Any ideas why?
Hi Ken,
I think what you are talking about is by design. As soon as you have more then the original web part on a list view page the item and list tab will disappear. In order to see it you have to click into the list first, otherwise SharePoint does not know which web parts properties you want to see/edit.
If i’m right with this assumption then I see no way to change this behavior at the moment. But i’ll have a look into it.
Duh. I didn’t think to try clicking on the web part – will try that tomorrow… If that works it’s fine the way it is…
if you click near by +newItem near by views you will get the items tab as well as list tab.
Thanks this works great!
the display works great with MS projects but it displays a box with a X when it comes to a pdf attachment. any ideas on a way to add a pdf icon?
many thanks again..
Hi Bill,
Please follow these instructions to get the PDF icon working:
http://phase2.com/blog/?p=258
Please remember to adjust the paths mentioned in that post. For SharePoint 2013 replace ../12/.. with ../15/..
Thanks for sharing your 2013 update, awesome.
phase2.com is down – not sure if forever or just for now. Any other links for enabling the PDF icon?
Thanks so much,
Joe
Hi Joe,
Just drop any icon you want into 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\IMAGES\'
Rename the icon to 'icpdf.gif' and that's it.
This is awesome, thanks! Unfortunately it seems not to work when I change the layout of the list view to "newsletter".. which was the look I was looking for (doing a news listing where users want to attach one or more files to a post).
Any suggestions?
Hi EHG,
thanks for the comment, glad you like it.
i'll have a look into it and update the script once its done.
Daniel
Daniel,
thanks for the reply. Would be really greateful if that functionality is added. Hopefully some more people would like that addition too!
Hi EHG,
good news, the script in version 2.3 works with the Newsletter style as well. Only requirement is that the ID column is included into the view. I have reintroduced the hideIdColumn-argument which will hide the ID column if you don't want to see it.
Please give it a try!
Daniel
Have just applied this solution to a couple of lists belonging to a customer, fantastically simple yet effective, cap doffed for the hard work and thanks for sharing.
Daniel,
Thanks for this, after long searches I finally found you and got excited about rolling it out.
Followed your instructions, but nothing happens and I have this error on my page:
Webpage error details
User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; .NET4.0E)
Timestamp: Fri, 5 Sep 2014 16:41:32 UTC
Message: Expected '}'
Line: 1367
Char: 19
Code: 0
URI: xxxxxx.com/Home.aspx
Message: 'g_spPreFetchKeys' is undefined
Line: 66
Char: 2
Code: 0
URI: xxxxxx.com/SiteAssets/ListAttachments_2.3.js
But no one else has any issues so think I might be doing something wrong. I only have a bit of HTML, no java experince at all.
Hi Scott,
the first error is caused by the properties object, there was a comma missing after "colorFont: 'white'". I corrected the article.
I'm not yet sure what is why the second error is popping up for you. I just tried the script again with the default masterpage in an unmodified environment where all the necessary code is put into a Script Editor Web Part and it's working fine for me.
Please try it again with the missing comma added, I hope its working for you then.
Daniel
Daniel,
Thanks, that got rid of the first error.
I have a list with ID, Attchment and Title column.
I paste the code into a CEWP (edit HTML option) and place that under the list.
Nothing changes when I do this, and I get an error alert.
When I run debug on the page it comes up with the same error:
Message: 'g_spPreFetchKeys' is undefined
Line: 66
Char: 2
I had a look at the code and it looks to be in the jquery part, so I even copied and pasted that locally rather than use ajax.google.etc but still same error.
Do you think it could be a versioning issue? Maybe my java or something is out of date?
aaand I just realised I was wasting your time trying to put this onto a SP2010 site.
Sorry about that, I grabbed the SP2010 version you based this off and it works fine.
Now just wating for the admins to update.
Hi Daniel,
I have followed instructions above. I am using SP 2013, ListAttachments_2.3.js and I have locally saved the jsquiery 1.9.1 in Site Assets.
I get the following errors from debugger. The paperclip does appear but nothing populates.
Error in parsing value for 'background'. Declaration dropped. AllItems.aspx:1
Unknown property '-moz-border-radius'. Declaration dropped. AllItems.aspx:1
Expected 'none' or URL but found 'alpha('. Error in parsing value for 'filter'. Declaration dropped. AllItems.aspx:1
Unknown property '-moz-opacity'. Declaration dropped.
I have tried v2.2. But I just get a spinning wheel and nothing populates.
Any idea?
Reuben
After more debugging I find the script skips over after not finding any class ids
line 206
table.find("tbody>tr:has(td[class^=ms-vb])").each(function () {
Hi Reuben,
Sounds tricky.
1. which browser and browser-version are you using?
2. Please tell me how your argObj looks like
3. If possible send me the HTML source of one of your SharePoint-pages (that contains a list and the script) via the contact form
Daniel
Hi Reuben,
Were you ever able to resolve the spinning wheel issue?
I am experiencing the same problem.
Thanks,
Josh
Hi Daniel,
thanks a lot for your work, it's a really useful script, and adds functionality to Sharepoint that should come by default.
I have it working, but I ran into two issues:
1) It doesn't work when the Attachments column is after a multiple-lines-text-column in the Newsletter view style, only when the Attachments column is before. See these screenshots:
http://patrick-nagel.net/misc/2015/01_Works_when_before_Description_column.png
http://patrick-nagel.net/misc/2015/02_Doesnt_work_when_after_Description_column.png
2) The hideIdColumn parameter works for the header of the table, but not for the body, which leads to the situation that the column headings are not in sync with the table content anymore. See these screenshots:
http://patrick-nagel.net/misc/2015/03_With_hideIdColumn-false.png
http://patrick-nagel.net/misc/2015/04_With_hideIdColumn-true.png
I'd be happy to assist with testing if you want to fix these! :)
Cheers,
Patrick.
Hi Patrick –
I've had this same problem. Were you ever able to find a fix?
Thanks,
Staci
And one more thing: I'd love to see a version where the paperclip actually gets replaced with (or appended by) the list of file names. That would be extremely useful for my use case (creating a PDF from a newsletter style "full text" view of a list).
Hi Daniel,
So first I tried this in a SEWP by itself and altered the script to reference the copy I downloaded and stored in a document library. But that didn't work.
Then I tried to reference the local copy with a CEWP. That didn't work.
Then I had the SEWP with the script in it referencing the local copy AND the CEWP referencing the local copy. This worked. It allowed me to hover over the paperclip and click on the attachments. However, the CEWP displays all the code that it seems to be executing. When I go to edit the CEWP and change the layout to hidden, it no longer executes.
I must be doing something wrong. Can you please give advice? I'm using SP 2013, Windows 7, and latest IE.
Thanks
I am using O365, SharePoint 2013, and I have managed to get this working on a ListView WebPart via SharePoint Designer. This is an awesome addition to the functionality of my list! Thanks for the share!!!
I have a bit of a problem, though. Maybe I'm not seeing this correctly, but I am not able to set more than 1 expected file extension for the image file that the script looks to retrieve. For instance, I needed to change Line 256 in the script to pull a .png for the PDF icon in src='/_layouts/15/images/ic" + item.ext + ".png'. I am getting the PDF icon now (and some others), but there are other icon file types that are not .png.
Can you create a sort-of wildcard extension for the retrieved icon file? The icon would then display no matter the extention and if not it would be the fault of the icon and not the script. Or is there another way to do this? Thanks again…
Hi, this works great except… I need it to work on lists that are grouped. What would I need to change to make this work on one level grouped lists?
New Version 2.4 worked great for me. AWESOME!!!
However, is there a reason PDF icons don't show?
I figured it out…
On line 254… I changed src to "_layouts/15/images/ic" and the extension from .gif to .png so it uses the SharePoint 2013 default icons. No icons are missed now.
Thanks again!
Using v2.4 of the script… I created a page with a web part containing a list with the attachments field visible and an script editor web part under it with the code snippet referencing local copies of the ListAttachments scripts. It does not work though. No popup, no errors, nothing. Please advise as I am really looking forward to this script. Thanks!
Hi,
Do you finally get this working for you? I run into the same issue.
No error but nothing happens…
I'm also using v2.4.
Below is the error I get when running the script. Any suggestions?
'L_Menu_BaseUrl' is undefined
Great script.
I made these changes
1) Correct location for icon filesin sharepoint 2013
wrapBuffer.push("<img id='customAtt_" + i + "_icon' style='vertical-align:middle; height: 16px; width: 16px' src='/_layouts/15/images/ic" + item.ext + ".png' border='0'> ");
2) If file name contains ' we have to handle it
item.fullPath = item.fullPath.replace("'","%27")
where does this go? in the new line or the existing line? item.fullPath + "' "
This is by far one of the best looking and easy to install Attachment Link in a List solutions I have found. One thing however, I installed the 2.4 version in my styles library, and it works great in a regular list view, however it seems to break (the link pops up and disappears right away) in a Standard View with Group enabled. Other than that, it's awesome, thank you for your wonderful work!
I've observed the same behavior.
Appreciated your efforts
However I had one glitch, when I was deploying the same code as a delegate control. As I required this functionality to all the lists (even if they are adding new lists), thus I injected script into masterpage with the help of delegate control (of course added as web level feature).
Problem: $("div#contentBox") was empty because this line of code is called before it is load contentBox element (by using delegate control)
$("div#contentBox").prepend("<div class='outerbubble' style='display: none' id='customAttPreviewWrapper'><div class='bubble' onmouseout='customMouseOutHideMenu(event, 1)'></div></div>");
Solution: Moved above mentioned code inside of ready function
Anyway this change may not be required for CEWP based solution.
Hi Daniel,
Great work!!
But when grouping applying in list view the pop up is not stable. some time appar and somtime not.
Thanks for this!
Now, how to make this work with asynchronously updated lists?
The point is that with asynchronous updates only the list data is updated/reloaded, without reloading the entire page/view… i.e. the script works only after the initial page load until the list content is updated in the background, then the balloons stop appearing (for obvious reasons).
Any idea?
I've had similar issues with JS in other instances and it always ended up being related to the minimal download strategy. Check out this post on the topic: http://blogs.msdn.com/b/sridhara/archive/2013/02/08/register-csr-override-on-mds-enabled-sharepoint-2013-site.aspx
Nope, it's not the case, MDS is not active on the site in question.
But, after reading the post I think that CSR is the way to go – 'hooking' the script to the "Body" field could do the trick… (sorry if I'm using incorrect terminology, I'm not a Sharepoint guy actually, just experimenting a bit)
We just ran into pretty much the same issue (specifically that after a search or 2, the attachment icons no longer had pop-ups/links) and were able to work around it by doing this:
1. Within the block of JS that starts with "thisWPContainer.each", change this:
if(argObj.clickToOpen) {
thisRow.find(">td:eq(" + attcolIndex + ")").find('img').attr('title', argObj.clickMouseover).css('cursor', 'pointer').click(function () {
showAtt(this, argObj);
});
} else {
thisRow.find(">td:eq(" + attcolIndex + ")").find('img').attr('title', '').mouseover(function () {
showAtt(this, argObj);
});
}
to this:
if(argObj.clickToOpen) {
thisRow.find(">td:eq(" + attcolIndex + ")").find('img').attr('title', argObj.clickMouseover).css('cursor', 'pointer').addClass('attachment-link').click(function () {
showAtt(this, argObj);
});
} else {
thisRow.find(">td:eq(" + attcolIndex + ")").find('img').attr('title', '').addClass('attachment-link').mouseover(function () {
showAtt(this, argObj);
});
}
The key thing to notice there is the addition of ".addClass('attachment-link')" in 2 places.
2. Add this at the end of the jQuery(document).ready function:
$(".ms-listviewtable").mouseenter(function() {
if (! $(this).find("tbody > tr > td img[src*='attach']").first().hasClass("attachment-link")) {
listAttachments(argObj);
}
});
Hi,
Thanks for the script!! it works like a charm however is there any know issues with IE 11? when I over the mouse on the paperclip, just nothing happen. I verified the settings of scripts execution and it seems all enabled. Any ideas?
Thanks
Hello
I have a problem with the script. On IE 11 the attachment preview isn't showing even though a few weeks ago it worked perfectly. Now we have to use Chrome or Firefox and its not the same since we always have to manually activate mixed content on both browsers.
Is there a way to make it work on Internet Explorer (version 11.0.9600.18015)?
Thanks and best regards
it is working for me but the PDF image icon doesnt come with expected result . it just show an square box only
Is it possible to put the pop-up on the title column?
Hello,
I'm just came across your post. We just got SP2013 and I'm trying to add the code to the List that I created but nothing comes up. Can you please advice?
Thanks! This is perfect and it worked perfectly well with our sp2013 site :D
Hello,
It worked for me in custom list..But I am using Visual Web part to search the Element from the same list and it will should show the attachment if attachment is available in search results….My question is that how to make this work for custom webpart solution..
Thank you So much..
Hi Dheeraj, can't help you on this one without knowing the HTML structure of the list-view in your webpart. Please contact me via daniel(at)spoodoo.com if you need help.
Hi,
I was able to successfully install this, but it appears that the hover/pop-up only works for people with admin access. I had a few "view-only" people try it on their laptops and it doesn't work for them. Nothing happens when they hover on the paperclip icon.
Does one have to have admin access to see this feature?
Hi Mae,
No, admin permission level is not necessary. What's necessary though is the "Use Remote Interfaces"-permission. The 'View Only' permission level should actually have this permission activated by default. Please check and activate it if it's deactivated.
Hi,
Where can I find the "Use Remote Interfaces" option?
Have a look here: https://technet.microsoft.com/en-us/library/cc263239.aspx
I checked and the "Use Remote Interfaces" is checked in all of our permission levels. That didn't fix anything. It appears that it only works in my computer but it doesn't work in others. Would this have to do with browser setting?
Just a little info that might help you troubleshoot….
* I'm using a list – each list item has attachments
* I created a site page where I've added the list to show inside a webpart. In this site page, I've pasted the script you've provided into the snippet.
It works perfectly on my computer. I can go hover on the paperclip and the pop-up shows where I can click on the attachment to download. For some weird reason, I'm the only one who can see it. In both the page/library settings (where the webpart is) and list settings, I have two groups in the permission (Admins = full control, Visitors = Read Only). I think the permissions are correct, but I just don't know why it doesn't show in my co-workers computers.
Hi,
It is working fine in Chrome and Firefox. Any idea on make it work in IE 10 and above?
FYI: I'm using ClicktoOpen as 'true'.
In IE, It appears and disappears quickly (like a blink)..
Waiting for reply..
Thanks,
Rajan
That bug should be fixed in the latest Beta.
Hello Daniel,
I am using 'ListAttachments_2.5.0BETA2.js' but still facing similar issue mentioned by Rajan.
in IE it appears and disappears like a blink.
Thanks,
Bhaskar Dhone
Hi ,
I am using this script 'ListAttachments_2.3 js' in Content editor web part,but i have error "g_spPreFetchKeys' is undefined" ,please help me how to fix this.
Hello, I'm using your script, but it does not seem to work for me.
I added a Script Editor web part. Then i pasted the code changing the url of the ListAttachments.js afterwards.
The .js file is located on a folder inside the shared documents (just for testing).
I'm seeing the same results. At first the hide ID part of the script editor worked but not the attachment hover.
Helo,
Its possible to make this "nice attachment buble" for Title column too?. What I need to change in code?. Thanks a lot. Dominik.
hi,
I need your help, i followed all the steps but nothing happen, i dont have any error message but its not working.
Please, can you help me?
in sp 2013 list once hover on attachment only spinning wheel showing nothing else i don't know what is the problem i followed your instructions and i am using v2.2 can somebody help me please.
Thanks
Yasir
Hi,
I got this script to work at my previous job, but for some reason it isn't working on SharePoint site I'm creating at my current job. I've uploaded the ListAttachments_2.5.0BETA2.js to our Scripts library. Changed the URL/Path on the script. Added the code in Snippet inside a webpart … and nothing happens. No errors or anything — just nothing.
What am I doing wrong?
Script works, but is anyone seeing that the pop-up bubble only comes up if you hit just the right spot on the paperclip and disappears quickly?
Thanks
I am putting the two script calls in a script editor on the page with the list and making sure that the current list attachments is in the Scripts folder in Site Assets (and is referenced from there).
The problem is that it does nothing. Is there something else I need to do to make this work?
Does this script work using JSLINK in the web part properties?
It should.
The bubble pops up and disappears again (blink/flash).
HOWEVER!!! When I approach the paperclip from the bottom and keep moving my mouse at just the right speed so that the pointer is at the bubble's position when the bubble appears, it will stay, but only then.
Using SP online/365.
Sharepoint 2013,
Put 2.5 script in siteassets -CEWP below view
no error in F12 developmenttools
added one alert line as first in script -> gets executed
ID Column did not vanish – must it be the first column?
Can someone please provide a 'step by step' of how to implement into SP2013. New to all this, but a definite need.
Thank you…
Would prefer to insert code within Script Editor Web Part on the page to implement and avoid uploading a '.js' file and referencing if possible?
Daniel,
I'm using SP 2013 online /O365. I cant get the script to render in Chrome or Firefox. its ok in IE11 but in Chrome there's some added security when trying to edit the list web part as in error message below. is this the reason why?
This page isn’t working
Chrome detected unusual code on this page and blocked it to protect your personal information (for example, passwords, phone numbers, and credit cards).
Try visiting the site's homepage.
ERR_BLOCKED_BY_XSS_AUDITOR
There have been some posts related to: "The bubble pops up and disappears again (blink/flash)." I see this behavior as well using IE. Daniel / anyone – has there been more discussion on this or a solution?
version 2.5 is not working for me. 2.4 is working perfectly! Daniel, could you please check version 2.5 again ?
Issue: Mouse Hover shows nothing. No error in console window, so unable to find what causing the issue.
for other guys that want to open attachment in browser with office online server or web app server, edit the source code and add the (+ "?web=1") to the end of *fullpath* attribute (line 143 in version 2.5.0)
like this:
fullPath: this.ServerRelativeUrl + "?web=1"
got it working with version 2.4, 2.5.0 wouldn't do anything at all.
Thanks. Great work.
Hi Daniel,
Thanks for the codes – they work great!. Now I’d like to export the list metadata and attachment names to excel but the file name doesn’t export. Any ideas on how to make that happen? – Stacy