0

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 the AutoHosted App using Client Side Object Model technology.

How can I achieve this functionality?

7
  • 1
    Are there problems with using like this code: thesharepointhelper.blogspot.se/2013/03/… ? Jun 18 '13 at 8:13
  • Yes sir I have created list like that. But I want list in My App. Not in SharePoint site... Jun 18 '13 at 8:25
  • By passing in the url to the app web it will be created in the App.. Jun 18 '13 at 8:47
  • Sir can you tell me how to pass the AppWebUrl to create List. And where to pass. Jun 18 '13 at 8:53
  • 1
    var webUrl = _spPageContextInfo.webServerRelativeUrl;pass in webUrl to the function creating the list Jun 18 '13 at 9:01
0

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.

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.