Pergunta

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?

Foi útil?

Solução

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();
    }
Licenciado em: CC-BY-SA com atribuição
Não afiliado a sharepoint.stackexchange
scroll top