Domanda

I have a SharePoint-hosted App-part (ClientWePart), and my app-part are dependent on a couple of lists to be created.

At the moment all my lists are created on the hostWeb _spPageContextInfo.siteAbsoluteUrl. I want my lists to be created on the site app-part are deployed on. I am using REST to create my lists when app is installed/deployed...

All my lists are created on:

http://app-7e2216cc1cce65.gonadnapps.com/sites/devsite

and my app URL is :

http://app-7e2216cc1cce65.gonadnapps.com/sites/devsite/manage/SimpliManageProsessModulH16

And my App-Part is deployed on URL:

http://app-7e2216cc1cce65.gonadnapps.com/sites/devsite/manage

And I want my lists to be created on the site URL above, "manage"...

I was also trying to find out to get Site Title of where my app-part are deployed.

È stato utile?

Soluzione 2

I solved it this way:

var spHostUrl = makeAbsUrl(_spPageContextInfo.webServerRelativeUrl.substring(0, _spPageContextInfo.webServerRelativeUrl.lastIndexOf("/")));

The reason for doing this is, I want my lists to be created on subsite name "manage", and not on the root site (siteAbsoluteUrl). And later I want all my REST call to point to the lists created under subsite "Manage".

Altri suggerimenti

If you're passing standard tokens when your app is opened, the SPHostUrl query string value will point back to the website where the app is hosted.

You can retrieve that value (and setup the AppContextSite if you're using the JSOM) with something like:

var qsVals = SP.ScriptHelpers.getDocumentQueryPairs(); //use the ScriptHelpers library
var hostWebUrl = decodeURIComponent(qsVals.SPHostUrl);
var clientContext = SP.ClientContext.get_current();
var appContextSite = new SP.AppContextSite(clientContext, hostWebUrl);

If you're using the cross domain library you'll have the host web URL value in hostWebUrl

If you need to go one level up or down you can use some string manipulation to navigate the URL hierarchy.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top