Home › Forums › vLooup for SharePoint › Using opening links using document library feature
Tagged: vlookup open file browser
- This topic has 16 replies, 5 voices, and was last updated 3 years, 6 months ago by Brian Oster.
-
AuthorPosts
-
-
September 11, 2019 at 19:13 #27050
Some time back I think you gave me some code that allowed me to define certain files shown using the “document library” feature with vLookup to open these files as files, not take the browser over. This works perfectly.
I am using FileLeafRef as the link to open the file, and some files are images. Is there a way to make any of the links (including images) visible open in a new window and not takeover the browser?
-
September 12, 2019 at 17:45 #27071
To help you I need to see the code you are using now – can you attach it here?
Please ensure you don’t include any sensitive information in the code snippet.
Alexander
-
September 12, 2019 at 18:05 #27073
I just sent you an email with the code I am using to force certain file types to download.
The title of this post is incorrect, so sorry about that. It should be: Opening links in a new window using the document library feature
-
September 12, 2019 at 19:06 #27075
Your emailed code worked perfectly, thank you!
-
-
October 7, 2019 at 13:10 #27252
hi, can you please share the script?
thank you -
October 19, 2019 at 08:12 #27407
Use this in the Special configuration textarea in your vLookup setup:
{"function":"showDownloadBtn"}
Then add this to your forms (all forms where you use vLookup) and if you use vLookup in a list view also add the function to the view (wrap it in a <script> tag and put it in a script editor web part in the page):
function showDownloadBtn(a, b) { var c = [], iArr = ["doc", "docx", "xls", "xlsx", "pptx"], v = b.get_item("FileLeafRef"), ext = v.split(".").pop(); if ($.inArray(ext, iArr) > -1) { // Proper method for other browsers - will open it in IE and not trigger a download c.push("<a href='" + b.get_item("FileDirRef") + "/" + v + "' download>Download</a>"); }else{ // All other documents open in a new tab c.push("<a href='" + b.get_item("FileDirRef") + "/" + v + "' target='_blank'>"+ v +"</a>"); // This will show the doc name - replace "+ v +" with the text Download if you like } return c.join(""); }
Alexander
- This reply was modified 5 years, 2 months ago by Alexander Bautz.
-
May 25, 2020 at 21:51 #30269
Hi Alex,
Believe this is related to this post, am trying to do the opposite thing than this lady.
When a user clicks on the Name of a file in the vlookup in a form, I want it to open the excel file in excel online, not in a _target=blank tab (which causes the file to download).
This mimics the default SP Doc library view where if you click on the file name it opens in O365 (excel online) does not download.
Setup – using Chrome btw and latest version of DFFS. (although would like it to force this behaviour in IE/Edge too)
list1 and a vlookup to library1 – library1 contains excel files.
In my list form, the vlookup uses FileLeafRef to show a link to open the excel document.
(LinkFilenameNoMenu,LinkFilename are computed and do not appear as links)
Guessing it might be a special function like above I need to add?
KR
Paul- This reply was modified 4 years, 7 months ago by Paul Lynch.
- This reply was modified 4 years, 7 months ago by Paul Lynch.
-
May 25, 2020 at 21:57 #30274
example of where where I am clicking
Attachments:
-
May 26, 2020 at 17:35 #30282
Hi,
You can do that by adding this to your Special configuration:{"function":"openInWeb"}
and this to your Custom JS:
function openInWeb(val, item){ var name = item.get_item("FileLeafRef"); var url = item.get_item("FileRef"); return "<a href='"+url+"?web=1' target='_blank'>"+name+"</a>"; }
Let me know how this works out.
Alexander
PS: This only works in Office 365.
-
May 26, 2020 at 20:33 #30286
This works perfectly thank you Alex
-
July 13, 2020 at 13:31 #30897
Sorry Alexander, I have a separate vLookup, with pdf’s only. Obviously not O365 MS application.
Is there anyway to force these to download (rather than open in browser), or even better open in Adobe (or prompt a choice)?
-
July 17, 2020 at 11:00 #30922
If you use old versions of IE or Edge this won’t work, but you can try modifying the link and add “download” like this:
return "<a href='"+url+"' download>"+name+"</a>";
This should automatically download it.
I cannot help with auto-opening in Adobe (unless it is the browser plugin – then clicking the link you already had should do it).
Alexander
-
August 13, 2020 at 16:13 #31192
Thanks for this Alexander, and good news about MS backing down.
My vLookup (configured within FORM1) uses a document library of excel files (FORM2)
Is it possible to;
– When user clicks to edit the vlookup item in table (FORM1)
– Get a pop up and see the Editform (FORM2) of the doc library item
– Within FORM2 pop up, have a html field, or script the Name field, so it becomes a link that opens excel in a new tab?The “Name” field doe not do this, unless it is in display form (although it downloads it rather than opens in a tab).
-
August 13, 2020 at 22:31 #31202
In your Document library EditForm add a HTML section with this div inside:
<div id="docLinkPlaceholder"></div>
Then add this to your Custom JS:
(function (){ var item = spjs.utility.getItemByID({ "listName":_spPageContextInfo.pageListId, "id":spjs.dffs.data.thisItemID, "viewFields":["ID","FileLeafRef","EncodedAbsUrl"] }); jQuery("#docLinkPlaceholder").html("<a href='"+item.EncodedAbsUrl+"?web=1' target='_blank'>"+item.FileLeafRef.split(";#")[1]+"</a>"); })();
Alexander
-
June 3, 2021 at 19:31 #33701
I was having the same issue as Paul in that I need to be able to click the link and edit the document and save changes back to the document in the list. The openInWeb function worked great for this.
However, is there a way to have it open in the Office Desktop App instead of the Web. I am not talking about the default behavior which is to download the document and then effectively edit it locally. I want the default behavior when viewing in native SP where you have the option to “Open in Word” or “Open in Excel” so that edits are saved back to the document in the doc lib. This way I can give users effectively the same option as “Open in Excel” or “Open in Excel Online”.
-
June 3, 2021 at 20:31 #33705
You can try creating a link like this:
"<a href='ms-word:ofe|u|"+item.EncodedAbsUrl+"' target='_blank'>"+item.FileLeafRef.split(";#")[1]+"</a>"
You can read about the Office URI Scheme here: https://docs.microsoft.com/en-us/office/client-developer/office-uri-schemes
Alexander
-
-
June 3, 2021 at 20:31 #33707
Ok, I think this works.
function openInWeb(val, item) { var name = item.get_item("FileLeafRef"); var url = item.get_item("FileRef"); return "<a href='" + url + "?web=1' target='_blank'>" + name + "</a>"; } function openInDesktopApp(val, item){ //debugger; var retlink = ""; var name = item.get_item("FileLeafRef"); var doctype = name.substring(name.lastIndexOf('.') + 1).toLowerCase(); var url = makeAbsUrl(item.get_item("FileDirRef") + "/" + name); switch(doctype) { case "doc" : case "docx" : retlink = "<a href='ms-word:ofe|u|" + url + "'>" + name + "</a>"; break; case "xls" : case "xlsx" : retlink = "<a href='ms-excel:ofe|u|" + url + "'>" + name + "</a>"; break; default: retlink = openInWeb(val, item); break; } return retlink; }
- This reply was modified 3 years, 6 months ago by Brian Oster.
- This reply was modified 3 years, 6 months ago by Brian Oster.
- This reply was modified 3 years, 6 months ago by Brian Oster.
-
-
AuthorPosts
- You must be logged in to reply to this topic.