3

I have a SharePoint add-in that create a "button" on the page ribbon. When the user clicks on the button, it makes a call to a provider hosted app that resides in Azure. The request goes through, but I need to know the URL of the page where the button was clicked. For example, the page where the icon is clicked is:

https://xxx.sharepoint.com/sites/TDC/en-us/SitePages/Test4.aspx

In my AppManifest.xml, I have the following:

<StartPage>https://yyy.azurewebsites.net?{StandardTokens}&amp;SPSource={Source}&amp;SPItemURL={ItemUrl}</StartPage>

In my elements.xml, I have the following:

<UrlAction Url="~remoteAppUrl/ContentExport.aspx?{StandardTokens}&amp;SPSource={Source}&amp;SPItemURL={ItemUrl}"></UrlAction>

<CommandUIHandler Command="Invoke_ContentExportAction3ButtonRequest"
                      CommandAction="~remoteAppUrl/ContentExport.aspx?{StandardTokens}&amp;SPSource={Source}&amp;SPItemURL={ItemUrl}"/>

The ItemUrl does not get resolved, which I believe makes sense for a StartPage. The source gives me the following:

SPSource='https://tdctranslations.sharepoint.com/sites/TDC/en-us/_layouts/15/commandui.ashx'

Is it possible to get the URL of Test4.aspx?

1 Answer 1

1

Can you try this -

  1. Get the current url of the SharePoint site.

    Asp.Net - System.Web.HttpContext.Current.Request.Path

    Javascript - window.location.href

  2. Pass it to the app as a url parameter -

    <url>?RequestSource='<path>'
    
  3. Decode it in the app

    Request.QueryString["RequestSource"];
    
3
  • How do I specify the javascript in the CommandAction as it needs to start with ~remoteAppUrl. CommandAction="javascript: .... does not work.
    – SaulR
    Jul 12, 2017 at 0:40
  • How are you redirecting the user on the button click, are you using href tag? or is it an aspx button? Jul 12, 2017 at 8:39
  • aspx button. Clicking on the icon in the ribbon causes an aspx page to be displayed. The user then fills out the information and clicks on a button at the bottom of the page. In the code behind for that aspx page, I need the URL of the page when the user clicked on the icon in the ribbon which is the itemUrl. In my elements.xml file, how can I add in the Javascript to get the current URL and pass that into the CommandAction.
    – SaulR
    Jul 12, 2017 at 16:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.