Create SharePoint-Hosted App in SharePoint 2013

This article will hnelp you   to create a  App in SharePoint2013 step-by-step. 

Create a farm solution and SharePoint-Hosted App
Use the following procedure to create a farm solution and SharePoint-Hosted App in Visual Studio 2012:
  1. Run Visual Studio as administrator, and choose "File" -> "New" -> "Project...".
  2. In the New Project dialog box, choose ".NET Framework 4.5" from the drop-down list at the top of the dialog box.
  3. In the Templates list, expand "Office/SharePoint", choose "Apps", and then choose the "App for SharePoint 2013" template.
  4. Name the project "SiteApp", and then choose the "OK" button.
  5. In the SharePoint Customization Wizard dialog box, choose "Deploy as a farm solution" and then choose the "Finish" button.
  6. In Solution Explorer, open the shortcut menu for the SiteApp project, and expand the Pages folder and click on the default.aspx page.
  7. In the markup of the "Default.aspx" file, paste the following code between the "Main" asp:Content tags. This code defines controls and script references.
  8. HTML<div>Site Name: <inputtype="text"id="siteName"value=""/>
  9. Open the "App.js" file under the Script folder. Replace with the following code:function getQueryStringValue(key) {
    var returnValue = "";
    var params = document.URL.split("?")[1].split("&");
    var strParams = "";
    for (var i = 0; i < params.length; i = i + 1) {
    var singleParam = params[i].split("=");
    if (singleParam[0] === key) {
    return decodeURIComponent(singleParam[1]);
        return returnValue;
    function createSite() {
        var hostWebUrl = getQueryStringValue("SPHostUrl");
        spcontext = 
    new SP.ClientContext.get_current();
    //then use the host web URL to get a parent context -this allows us to get data from the parent    parentCtx = new SP.AppContextSite(spcontext, hostWebUrl);
        currentWeb = parentCtx.get_web();
        context.executeQueryAsync(onCreationSuccess, OnFailure);
    function onCreationSuccess() {
    "In onCreationSuccess");
    var appInstanceID = currentWeb.get_appInstanceId();
    var webCreateInfo = new SP.WebCreationInformation();
    "This site created from Javascript");
    var site = $("#siteName").val();
        webCreateInfo.set_webTemplate("COMMUNITY#0");// you can add webtemplate as per your choice    web = currentWeb.get_webs().add(webCreateInfo, false, appInstanceID);
        context.executeQueryAsync(onSuccess, OnFailure);
    function onSuccess() {
    "Web created");
    function OnFailure(sender, args) {
  10. Open the "AppManifest.xml" file and set the permission to "Site Collection as Full Control".
once you created the app please deploy and add the app in site,you can create a site in sharepoint using this app.

Hope you have liked my article.

Post a Comment

Previous Post Next Post

Recent Posts