1

Am creating a vanilla Napa app and am seeking to reference the host URL as follows:

var ctx = new SP.ClientContext(_spPageContextInfo.webServerRelativeUrl);

Yet _spPageContextInfo is being flagged as undefined. From what I have read this should be baked into SharePoint, so I cannot understand why it is not defined.

I'm sure the solution is simple, but can someone please advise?

5 Answers 5

1

you need to add the "SharePoint:SharePointForm" control to your page body.

enter link description here

0

Look at this extremely similar question Accessing a list from app web on host site generates access denied

It has the answer I suppose!

2
  • Similar, but not a duplicate as I see it ;-)
    – SPDoctor
    May 30, 2013 at 8:54
  • No I realized it was not the same question, but the same answer ;) May 30, 2013 at 8:54
0

In order to benefit from these URLs you would need to pass in the proper Tokens, which can than be retrieved as explained here http://msdn.microsoft.com/en-us/library/jj163816.aspx and http://msdn.microsoft.com/en-us/library/fp179886.aspx

I would even argue that _spPageContextInfo is not to be used in the a SharePoint app (mainly used it in Farm solutions) but rather use the token to build your context properly. Examples for using JSOM available also here http://msdn.microsoft.com/library/jj163201.aspx

0

_spPageContextInfo can be used in a page in a SharePoint-Hosted app. You will get a "squigly" in the editor because it the _spPageContextInfo object is added to the page dynamically, thus the editor is not aware of it.

Simple example using _spPageContextInfo :

enter image description here

enter image description here

0

You don't have to necessarily reference a master page in your SharePoint app to get _spPageContextInfo to load.

What is required is the addition of the <asp:ScriptMananger> control to your App or AppPart page. The control has to live in a <form runat="server"> so be sure to add that too.

    <body>

    <form runat="server">
    <asp:ScriptManager id="ScriptManager" runat="server" EnablePageMethods="false" EnablePartialRendering="true" EnableScriptGlobalization="false" EnableScriptLocalization="true" />
<!-- Your code goes here -->
    </form>
</body>
1
  • Using a webform in a Provider-Hosted app, I haven't been able to get this to work - I still get "_spPageContextInfo is not defined" Do you have more information on this? Oct 27, 2014 at 12:04

Your Answer

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

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