3

Is it possible to add an app file to app catalog from the file system using CSOM? I having app in my local machine, i want to upload this to app catalog using CSOM. There are article to add app to site, but not able to find upload app to app catalog from CSOM. Any leads?

2

We can use the ALM APIs with CSOM for this.

Ensure that you have the latest PnP Core version or atleast a version above November 2017.

After that, you can upload it as below:

1) Using File path

string webUrl = "https://tenant-name.sharepoint.com/sites/appcatalog/";

string username = "user.name@tenantname.onmicrosoft.com";
string password = "password";
SecureString secureString = new SecureString();
password.ToList().ForEach(secureString.AppendChar);
var credentials = new SharePointOnlineCredentials(username, secureString);

using (ClientContext ctx = new ClientContext(webUrl))
{
    ctx.Credentials = credentials;

    var appManager = new AppManager(ctx);

    var path = @"C:\temp\HelloWorld.sppkg";

    var uploadApp = appManager.Add(path, true);

}

2) Using byte array

string webUrl = "https://tenant-name.sharepoint.com/sites/appcatalog/";

string username = "user.name@tenantname.onmicrosoft.com";
string password = "password";
SecureString secureString = new SecureString();
password.ToList().ForEach(secureString.AppendChar);
var credentials = new SharePointOnlineCredentials(username, secureString);

using (ClientContext ctx = new ClientContext(webUrl))
{
    ctx.Credentials = credentials;

    var appManager = new AppManager(ctx);

    var path = @"C:\temp\HelloWorld.app";

    byte[] file = System.IO.File.ReadAllBytes(path);

    var uploadApp = appManager.Add(file, "HelloWorld.app", true);

}

Also, if you have PnP PowerShell, you can use the Add-PnPApp method as below:

Add-PnPApp -Path ./helloWorld.sppkg

If you want to upload it to a site collection app catalog, just modify the parameter and mention the scope.

Reference - Add-PnPApp

0

App Catalog is also a SharePoint library, where you can directly access the files. You can upload the app file as Stream in it. I have not checked that. But we can access the Catalog using the same way we access lists and libraries.

  • Thank you. But question is not about accessing file from app catalog, adding app to app catalog using CSOM. – Mihir Jun 12 '18 at 13:28

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.