0

I have a provisioning script which is run as a web job where i need to create a site collection app catalog and then add an app to it. I am storing information about the site in a sharepoint library which contains various xml, as well as the app. it then provisions the site successfully, creates the app catalog but no app inside. Checking the error logs it is stating that the file cannot be found.

I have the following code:

                var appcat = web.SiteCollectionAppCatalog;
                var appManager = new AppManager(context);

                var path = https://tenant.sharepoint.com/sites/sitename/siteassets/appname.sppkg;
                var uploadApp = appManager.Add(path, true, OfficeDevPnP.Core.Enums.AppCatalogScope.Site); // This is where it errors saying file does not exist
                web.Update();
                context.ExecuteQuery();

Is it possible to upload from a different sharepoint site? if so where am i going wrong, if not what would the alternatives be if it cannot be in local storage? Azure Storage?

1 Answer 1

0

You could try the below:

    var appManager = new AppManager(context);
    var file = web.GetFileByUrl("https://tenant.sharepoint.com/sites/test/SiteAssets/app.sppkg");
    ClientResult<System.IO.Stream> data = file.OpenBinaryStream();

    context.Load(file);
    context.ExecuteQuery();
    using (MemoryStream memoryStream = new MemoryStream())
    {
        data.Value.CopyTo(memoryStream);
        byte[] fileArray = memoryStream.ToArray();
        var uploadApp = appManager.Add(fileArray, file.Name,true, OfficeDevPnP.Core.Enums.AppCatalogScope.Site) ;
        web.Update();
        context.ExecuteQuery();
    }
1
  • thanks, works perfectly. sorry for the delay in marking as answer Dec 7, 2020 at 13:27

Your Answer

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

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