2

I am developing a sharepoint hosted app and I want to create custom list using Visual Studio 2013.

I want to create the custom list in host web using VS and deploy it to sharepoint 2013 online.

I don't have sharepoint 2013 locally installed on my machine. Can I create the list and how ?

Thanks in advance.

2 Answers 2

2

Yes you can create a list in host web. The only thing is you need to give "Manage" right to web in your AppManifest.xml. Using REST the code will be:

jQuery.ajax({
    url: “http://site url/_api/web/lists”,
    type: "POST",
    data:  JSON.stringify({ '__metadata': { 'type': 'SP.List' }, 'AllowContentTypes': true, 'BaseTemplate': 100, 'ContentTypesEnabled': true, 'Description': 'My list description', 'Title': 'Test' }),
    headers: { 
        "accept": "application/json;odata=verbose",
        "content-type": "application/json;odata=verbose",
        "content-length": length of post body,
        "X-RequestDigest": $("#__REQUESTDIGEST").val()
    },
    success: doSuccess,
    error: doError   
});

Check this msdn link for complete details.

0

If a list is to be deployed in App web then one can easily use the declarative XML, for example by using List Definition. However, if the list is to be deployed to Host web, then declarative XML cannot be used. In this case the list can be provisioned using CSOM. Follwoing is the code snippet for creating a list in Host Web:

function createlist() {
        // Create an announcement SharePoint list with the name that the user specifies.
        var hostUrl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
        var currentcontext = new SP.ClientContext.get_current();
        var hostcontext = new SP.AppContextSite(currentcontext, hostUrl);
        hostweb = hostcontext.get_web();
        var listCreationInfo = new SP.ListCreationInformation();
        var listTitle = document.getElementById("createList").value;
        listCreationInfo.set_title(listTitle);
        listCreationInfo.set_templateType(SP.ListTemplateType.announcements);
        var lists = hostweb.get_lists();
        var newList = lists.add(listCreationInfo);
        context.load(newList);
        context.executeQueryAsync(onListCreationSuccess, onListCreationFail);
    }

    function onListCreationSuccess() {
        alert('List created successfully!');
    }

    function onListCreationFail(sender, args) {
        alert('Failed to create the list. ' + args.get_message());
    }

See more at: http://sharepointnadeem.blogspot.in/2013/12/sharepoint-2013-apps-access-data-in.html

Your Answer

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

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