Beispiel #1
0
        /// <summary>
        /// Uploads a design package to a library. Can be used for uploading sandboxed solutions to solution gallery.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="localFilePath">Path to package (wsp)</param>
        public void UploadDesignPackageToSiteAssets(ClientContext context, string localFilePath)
        {
            var fileName      = Path.GetFileName(localFilePath);
            var fileExtension = Path.GetExtension(fileName);

            if (fileExtension != null && fileExtension.ToLower() != ".wsp")
            {
                throw new NotSupportedException("Only WSPs can be uploaded into the SharePoint solution store. " +
                                                localFilePath + " is not a wsp");
            }
            if (string.IsNullOrEmpty(fileName) || _urlToWeb == null)
            {
                throw new Exception("Could not create path to solution package!");
            }

            var siteAssetsLibrary = context.Web.Lists.EnsureSiteAssetsLibrary();

            context.Load(siteAssetsLibrary);
            context.Load(siteAssetsLibrary.RootFolder);
            context.ExecuteQuery();

            if (_isSharePointOnline)
            {
                var fileUrl = UriUtilities.CombineAbsoluteUri(_urlToWeb.GetLeftPart(UriPartial.Authority), siteAssetsLibrary.RootFolder.ServerRelativeUrl, fileName);
                UploadFileToSharePointOnline(context, localFilePath, fileUrl);
            }
            else
            {
                UploadFileToSharePointOnPrem(context, localFilePath, fileName);
            }
        }