Ejemplo n.º 1
0
        private void SetupView(ClientContext context, List list, ShView view)
        {
            var  viewCollection = list.Views;
            View setupView      = null;

            if (!string.IsNullOrEmpty(view.Title))
            {
                setupView = viewCollection.FirstOrDefault(v => v.Title == view.Title);
                if (setupView == null)
                {
                    setupView = viewCollection.Add(GetViewCreationInfoFromConfig(view));
                    context.ExecuteQuery();
                }
            }
            else if (!string.IsNullOrEmpty(view.Url))
            {
                context.Load(list, x => x.ParentWebUrl);
                context.Load(list, x => x.ParentWeb);
                context.ExecuteQuery();

                var serverRelativeUrl = UriUtilities.CombineServerRelativeUri(list.ParentWebUrl, view.Url);
                list.ParentWeb.CheckOutFile(serverRelativeUrl);
                setupView = viewCollection.FirstOrDefault(v => v.ServerRelativeUrl == serverRelativeUrl);
            }
            if (setupView != null)
            {
                if (view.ViewFields.Length > 0)
                {
                    setupView.ViewFields.RemoveAll();
                    foreach (var field in view.ViewFields)
                    {
                        setupView.ViewFields.Add(field);
                    }
                }
                setupView.JSLink    = view.JSLink;
                setupView.ViewQuery = view.Query;
                setupView.RowLimit  = view.RowLimit;

                setupView.Update();
                if (!string.IsNullOrEmpty(view.Url))
                {
                    list.ParentWeb.CheckInFile(setupView.ServerRelativeUrl, CheckinType.MajorCheckIn, "updated by sherpa");
                }
                context.ExecuteQuery();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Activates a design package based on package name
        /// Starting point: http://sharepoint.stackexchange.com/questions/90809/is-it-possible-to-activate-a-solution-using-client-code-in-sharepoint-online-201
        /// </summary>
        /// <param name="context"></param>
        /// <param name="filePathOrName">The filename of the package</param>
        /// <param name="siteRelativeUrlToLibrary">Site relative URL to the library of the package</param>
        public void ActivateDesignPackage(ClientContext context, string filePathOrName, string siteRelativeUrlToLibrary)
        {
            // if we pass in a full path, correct this
            var nameOfPackage = Path.GetFileNameWithoutExtension(filePathOrName);

            context.Load(context.Site);
            context.Load(context.Web);
            context.ExecuteQuery();

            var stagedFileUrl = UriUtilities.CombineServerRelativeUri(context.Site.ServerRelativeUrl, siteRelativeUrlToLibrary, nameOfPackage + ".wsp");
            var packageInfo   = GetPackageInfoWithLatestVersion(context, nameOfPackage, stagedFileUrl);

            Log.Info("Installing solution package " + GetFileNameFromPackageInfo(packageInfo));
            DesignPackage.Install(context, context.Site, packageInfo, stagedFileUrl);
            context.ExecuteQuery();

            DeleteFile(context, stagedFileUrl);
        }