Domanda

I am developing Apps for SharePoint 2013. And I want to create Multiple list in My App Package programmatically.
It is like user inputs Name of list and when he clicks the Create Button the list with the same name should be created in my App not in SharePoint site.

I have created an AutoHosted App in which I have used Client Side Object Model technology.

How can I achieve this functionality?

È stato utile?

Soluzione

I have found the solution.
When I was creating the ContextToken object in that I was passing the SPHostUrl of the request but instead of that I passed SPAppWebUrl So using that it get the token of the AppWebUrl and thus it created the list in my App not in SharePoint site.

Like bellow code:

var hostWeb = Page.Request["SPAppWebUrl"]; //This will get the URL of AppWeb not SharePoint site...

using (var clientContext = TokenHelper.GetClientContextWithContextToken(hostWeb, ContextToken, Request.Url.Authority))
{
     //Code for creating list or manipulating them...
     //This ClientContext is created for the AppWeb.
}

When I was searching the code for creating every time I was finding the hostWeb object is created using SPHostUrl Therefore I asked this question.
Thank you everyone for your help.

Altri suggerimenti

You can use the JavaScript Client Object Model to create the list in the App. There's a code example demonstrating how to do so here:

http://msdn.microsoft.com/en-us/library/jj163201.aspx#BasicOps_SPListCRUD

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top