0

I have deployed a custom ribbon button and when a user clicks it, I open a custom application page - I have deployed the page to _layouts mapped folder. To open the page (with JavaScript), so far I'm providing an absolute URL which looks like this:

targetUrl = 'http://srvr/sites/Site1/_layouts/MyProject/AppPage.aspx';

where http://srvr/sites/Site1 is the "Site URL" property of my Visual Studio project (deployed as a farm solution).

My question is: how do I determine the URL of AppPage.aspx independently of the environment, i.e. in a relative manner? E.g. if I deploy to a farm where "Site1" doesn't exist, in what way should I construct the target URL? I assume what I'm trying to do is to deploy the application page in a way that won't rely on the existence of 'Site1' site collection. Would deploying to _admin mapped folder instead of _layouts make sense (I want the app page to be viewable by normal users, not just admins)?

(UPDATE) Here's the complete JS code that I use to open the application page (as a dialog):

function OpenMyAppPage() {   
    var options = SP.UI.$create_DialogOptions();
    options.url = 'http://srvr/sites/Site1/_layouts/MyProject/AppPage.aspx';
    options.url += "?Location=" + location.href;
    options.width = 400;
    options.height = 200;
    options.allowClose = false;
    options.allowMaximize = false;
    options.title = 'Example';
    SP.UI.ModalDialog.showModalDialog(options);
}

Note: simply changing the url to '/_layouts/MyProject/AppPage.aspx' gives me error 404.

  • Does it work to go to 'srvr/_layouts/MyProject/AppPage.aspx' in the browser? If not, you have not added the page to the mapped layouts folder but rather to your own _layouts/MyProject folder locally on /sites/Site1 – Robert Lindgren Feb 20 '14 at 10:08
  • It doesn't work (404), so this seems to be the problem. This question has a picture of how I have things set up in VS for a similar project. What I have done is: I added SharePoint "Layouts" Mapped Folder via VS project context menu (right click -> add); inside the Layouts folder, there is MyProject folder with the application page inside. From what I've read, this seems to be the way to do it, but looks like I'm wrong? – w128 Feb 20 '14 at 10:20
  • That sounds correct, but have you pushed down the changes to the Root by doing a new deploy or Update-SPSolution or Copy To Root with for example CKSDev? – Robert Lindgren Feb 20 '14 at 10:25
4

Would this not work? Using the fact that Layouts is shared through the fram

targetUrl = '/_layouts/MyProject/AppPage.aspx' + "?Location=" + window.location.href;

or you could try:

targetUrl = SP.Utilities.Utility.getLayoutsPageUrl('MyProject/AppPage.aspx' + "?Location=" + window.location.href)
  • Thanks, but I tried this already and unfortunately it results in 404 (not found). – w128 Feb 20 '14 at 9:40
  • Well the information that you are using a SP.ModalDialog would have been helpful to start with ;) – Robert Lindgren Feb 20 '14 at 10:01
  • Sorry about that! :) I'm pretty new to the front end stuff so there are plenty of unknown unknowns. – w128 Feb 20 '14 at 10:11
  • Indeed the second solution works. One thing that isn't clear to me though is that the url constructed is /sites/Site1/_layouts/MyProject/AppPage.aspx - notice that the solution still depends on the existence of "Site1"; if I get this correctly, if I deploy this to another server/url (where no Site1 exists), it should work automatically? Basically I'm just confused about the implications of "Site URL" project property in VS, but I guess that's a new question... – w128 Feb 20 '14 at 10:33
0

Try changing the options.Url to:

 options.url = _spPageContextInfo.webServerRelativeUrl+'/_layouts/MyProject/AppPage.aspx';

Edit: Didn't notice 2010 first, updated with webServerRelativeUrl

  • Thanks, but no luck: this results in a runtime error when I open the page. – w128 Feb 20 '14 at 9:55

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.