1

I need a Menu Item Custom Action for a Document Library that opens the document with a different URL prefix.

We have an application that has a URI handler for abc://SharePoint/Docs/Document.pdf that when clicked Windows will know to use the application to open this type of link. Similar to Skype clickable links: skype://

So the UrlAction needs to be the URL of the document but with a different URL prefix.

<CustomAction Id="f95c280d-88fb-43ae-bef3-589efd3d3f5a.MenuItemCustomAction1"
    RegistrationType="List"
    RegistrationId="101"
    Location="EditControlBlock"
    Sequence="120"
    Title="Open in Trapeze">
<UrlAction Url="abc://linkToDocument" />
</CustomAction>

How can I make use of the URLAction to replace http/https of the SiteUrl with abc?

1

In SharePoint 2013 you cannot use JavaScript in the URLAction therefore I have solved the problem by including the JS in the page the link directs to.

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
 <CustomAction Id="f95c280d-88fb-43ae-bef3-589efd3d3f5a.MenuItemCustomAction1"
        RegistrationType="List"
        RegistrationId="101" 
        Location="EditControlBlock"
        Sequence="120" 
        Title="Open in Trapeze">
  <UrlAction Url="~appWebUrl/pages/default.aspx?HostUrl={HostUrl}&amp;SPItemURL={ItemUrl}" />
 </CustomAction>
</Elements>

I have included the HostUrl and ItemUrl into the Get request so that I can use the information on the next page.

App.js:

var hostweburl = GetUrlKeyValue("HostUrl");
var ItemUrl = GetUrlKeyValue("SPItemURL");
var b = hostweburl.split("://")[1];
var SiteCollection = b.split("/")[0];
var newURL = "abc://" + SiteCollection + ItemUrl
var noSpaceNewURL = newURL.replace(/\s/g, "%20");

$(document).ready(function () {
    openNewProtocol();
});

function openNewProtocol() {
    window.location = noSpaceNewURL;
    $('#message').text('If the document does not load please click the below link');
    document.querySelector('#linkdesc').innerHTML = newURL
    document.getElementById("newlink").href = noSpaceNewURL;
}

function goBack() {
    window.history.back();
}

Default.aspx (has reference to App.js)

<asp:Content ContentPlaceHolderID="PlaceHolderMain" runat="server">
<div>
    <p id="message"></p>
    <p>
        Trapeze Link: <a href="#" id="newlink">
                            <span id="linkdesc"></span>
                      </a>
    </p>
    <br />
    <p>
        <a href="javascript:goBack();">Click here to go back</a>
    </p>
</div>
</asp:Content>

The above solution redirects the user to a page where the document opens up in the abc application. The page gives the user an option to click the link to reopen doc in the application or click to go back.

It would be better to skip out the page altogether, however as the Elements.xml does not allow JavaScript in SharePoint 2013 (it does in 2010) the holding page is required.

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.