none
How to add remotely an app in site content using C# or PowerShell

    Question

  • Hi

    How can I remotely add in site content an app already deployed in the App Catalog ?

    Regards,

    Arioule


    arioule

    Saturday, February 10, 2018 12:29 AM

Answers

  • Hi,

    Check the thread shared by Vesa Juvonen.

    Sample code:

    // Unique ID for side loading feature
    Guid sideloadingFeature = new Guid("AE3A1339-61F5-4f8f-81A7-ABD2DA956A7D");
    // Prompt for URL
    string url = GetUserInput("Please provide URL for the site where app is being installed: \n");
    // Prompt for Credentials 
    Console.WriteLine("Enter Credentials for {0}", url);
    string userName = GetUserInput("SharePoint username: ");
    SecureString pwd = GetPassword();
     
    // Get path to the location of the app file in file system
    string path = GetUserInput("Please provide full path to your app package: \n");
     
    // Create context for SharePoint online
    ClientContext ctx = new ClientContext(url);
    ctx.AuthenticationMode = ClientAuthenticationMode.Default;
    ctx.Credentials = new SharePointOnlineCredentials(userName, pwd);
     
    // Get variables for the operations
    Site site = ctx.Site;
    Web web = ctx.Web;
     
    try
    {
        // Make sure we have side loading enabled. 
        // Using PnP Nuget package extensions.
        site.ActivateFeature(sideloadingFeature);
        try
        {
            // Load .app file and install that to site
            var appstream = System.IO.File.OpenRead(path);
            AppInstance app = web.LoadAndInstallApp(appstream);
            ctx.Load(app);
            ctx.ExecuteQuery();
        }
        catch
        {
            throw;
        }
        // Disable side loading feature using 
        // PnP Nuget package extensions. 
        site.DeactivateFeature(sideloadingFeature);
    }
    catch (Exception ex)
    {
        Console.ForegroundColor = ConsoleColor.Red;
        Console.WriteLine(string.Format("Exception!"), ex.ToString());
        Console.WriteLine("Press any key to continue.");
        Console.Read();
    }

    https://blogs.msdn.microsoft.com/vesku/2015/11/20/automating-add-inapp-installation-to-sharepoint-sites-using-csom/

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    • Proposed as answer by LinyusMVP Monday, February 12, 2018 6:46 AM
    • Marked as answer by Kabylie Monday, February 19, 2018 9:01 AM
    Monday, February 12, 2018 3:15 AM
  • Hi Kabylie, 

    Kindly refer the below article to deploy an add-in from app catalog using powershell.

    https://blog.robgarrett.com/2016/05/09/deploying-a-sharepoint-add-in-from-the-catalog-via-powershell/


    Ramakrishnan

    • Marked as answer by Kabylie Monday, February 19, 2018 9:02 AM
    Saturday, February 10, 2018 3:02 AM
  • Thanks a lot Lee

    arioule

    • Marked as answer by Kabylie Tuesday, March 6, 2018 9:37 AM
    Friday, February 16, 2018 3:20 PM
  • Hi,

    You can mark the helpful post as answer, so it may help other community members find the helpful information quickly.

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    • Marked as answer by Kabylie Monday, February 19, 2018 9:02 AM
    Monday, February 19, 2018 8:58 AM

All replies

  • Hi

    How can I remotely add in site content an app already deployed in the App Catalog ?

    Regards,

    Arioule


    arioule


    Saturday, February 10, 2018 12:28 AM
  • Hi Kabylie, 

    Kindly refer the below article to deploy an add-in from app catalog using powershell.

    https://blog.robgarrett.com/2016/05/09/deploying-a-sharepoint-add-in-from-the-catalog-via-powershell/


    Ramakrishnan

    • Marked as answer by Kabylie Monday, February 19, 2018 9:02 AM
    Saturday, February 10, 2018 3:02 AM
  • Hi,

    Check the thread shared by Vesa Juvonen.

    Sample code:

    // Unique ID for side loading feature
    Guid sideloadingFeature = new Guid("AE3A1339-61F5-4f8f-81A7-ABD2DA956A7D");
    // Prompt for URL
    string url = GetUserInput("Please provide URL for the site where app is being installed: \n");
    // Prompt for Credentials 
    Console.WriteLine("Enter Credentials for {0}", url);
    string userName = GetUserInput("SharePoint username: ");
    SecureString pwd = GetPassword();
     
    // Get path to the location of the app file in file system
    string path = GetUserInput("Please provide full path to your app package: \n");
     
    // Create context for SharePoint online
    ClientContext ctx = new ClientContext(url);
    ctx.AuthenticationMode = ClientAuthenticationMode.Default;
    ctx.Credentials = new SharePointOnlineCredentials(userName, pwd);
     
    // Get variables for the operations
    Site site = ctx.Site;
    Web web = ctx.Web;
     
    try
    {
        // Make sure we have side loading enabled. 
        // Using PnP Nuget package extensions.
        site.ActivateFeature(sideloadingFeature);
        try
        {
            // Load .app file and install that to site
            var appstream = System.IO.File.OpenRead(path);
            AppInstance app = web.LoadAndInstallApp(appstream);
            ctx.Load(app);
            ctx.ExecuteQuery();
        }
        catch
        {
            throw;
        }
        // Disable side loading feature using 
        // PnP Nuget package extensions. 
        site.DeactivateFeature(sideloadingFeature);
    }
    catch (Exception ex)
    {
        Console.ForegroundColor = ConsoleColor.Red;
        Console.WriteLine(string.Format("Exception!"), ex.ToString());
        Console.WriteLine("Press any key to continue.");
        Console.Read();
    }

    https://blogs.msdn.microsoft.com/vesku/2015/11/20/automating-add-inapp-installation-to-sharepoint-sites-using-csom/

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    • Proposed as answer by LinyusMVP Monday, February 12, 2018 6:46 AM
    • Marked as answer by Kabylie Monday, February 19, 2018 9:01 AM
    Monday, February 12, 2018 3:15 AM
  • Thanks a lot Lee

    arioule

    • Marked as answer by Kabylie Tuesday, March 6, 2018 9:37 AM
    Friday, February 16, 2018 3:20 PM
  • Hi,

    You can mark the helpful post as answer, so it may help other community members find the helpful information quickly.

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    • Marked as answer by Kabylie Monday, February 19, 2018 9:02 AM
    Monday, February 19, 2018 8:58 AM
  • Thanks a lot for your help.

    Regards,

    Arioule

    arioule

    Tuesday, March 6, 2018 9:37 AM