public static MasterPageInfo GetMasterPageInfo(Web web)
        {
            MasterPageInfo mpi = new MasterPageInfo();

            try
            {
                Logger.LogInfoMessage(String.Format("Getting Master Page info for: {0} ...", web.Url), false);

                web.Context.Load(web.AllProperties);
                web.Context.ExecuteQuery();

                mpi.MasterPageUrl       = web.MasterUrl;
                mpi.CustomMasterPageUrl = web.CustomMasterUrl;
                mpi.InheritMaster       = web.AllProperties[Constants.PropertyBagInheritMaster].ToString().ToBoolean();
                mpi.InheritCustomMaster = web.AllProperties[Constants.PropertyBagInheritCustomMaster].ToString().ToBoolean();
            }
            catch (Exception ex)
            {
                Logger.LogErrorMessage(String.Format("GetMasterPageInfo() failed for {0}: Error={1}", web.Url, ex.Message), false);
            }

            return(mpi);
        }
Esempio n. 2
0
        public static void SetMasterPages(Web web, MasterPageInfo mpi, bool isRoot)
        {
            try
            {
                Logger.LogInfoMessage(String.Format("Setting Master Pages to: {0} & {1}...", mpi.MasterPageUrl, mpi.CustomMasterPageUrl), false);

                Logger.LogInfoMessage(String.Format("MasterUrl (before): {0}", web.MasterUrl), false);
                Logger.LogInfoMessage(String.Format("CustomMasterUrl (before): {0}", web.CustomMasterUrl), false);

                web.Context.Load(web.AllProperties);
                web.Context.ExecuteQuery();

                web.MasterUrl = mpi.MasterPageUrl;
                web.CustomMasterUrl = mpi.CustomMasterPageUrl;
                web.AllProperties[Constants.PropertyBagInheritMaster] = ((!isRoot && mpi.InheritMaster) ? "True" : "False");
                web.AllProperties[Constants.PropertyBagInheritCustomMaster] = ((!isRoot && mpi.InheritCustomMaster) ? "True" : "False");
                web.Update();
                web.Context.ExecuteQuery();

                Logger.LogSuccessMessage(String.Format("MasterUrl (after): {0}", web.MasterUrl), false);
                Logger.LogSuccessMessage(String.Format("CustomMasterUrl (after): {0}", web.CustomMasterUrl), false);
            }
            catch (Exception ex)
            {
                Logger.LogErrorMessage(String.Format("SetMasterPages() failed for {0}: Error={1}", web.Url, ex.Message), false);
            }
        }
Esempio n. 3
0
        public static MasterPageInfo GetMasterPageInfo(Web web)
        {
            MasterPageInfo mpi = new MasterPageInfo();
            try
            {
                Logger.LogInfoMessage(String.Format("Getting Master Page info for: {0} ...", web.Url), false);

                web.Context.Load(web.AllProperties);
                web.Context.ExecuteQuery();

                mpi.MasterPageUrl = web.MasterUrl;
                mpi.CustomMasterPageUrl = web.CustomMasterUrl;
                mpi.InheritMaster = web.AllProperties[Constants.PropertyBagInheritMaster].ToString().ToBoolean();
                mpi.InheritCustomMaster = web.AllProperties[Constants.PropertyBagInheritCustomMaster].ToString().ToBoolean();
            }
            catch (Exception ex)
            {
                Logger.LogErrorMessage(String.Format("GetMasterPageInfo() failed for {0}: Error={1}", web.Url, ex.Message), false);
            }

            return mpi;
        }