Exemplo n.º 1
0
        /// <summary>
        /// </summary>
        public static bool CheckInSPFile(SpConnectionManager spConnection,
                                         Guid listId,
                                         string fileServerRelUrl,
                                         string comment,
                                         CheckinType checkinType,
                                         out string msg)
        {
            msg = "";

            try
            {
                using (var ctx = spConnection.GetContext())
                {
                    var file = ctx.Web.GetFileByServerRelativeUrl(fileServerRelUrl);

                    ctx.Load(file, f => f.Name, f => f.ListItemAllFields, f => f.ServerRelativeUrl);
                    ctx.ExecuteQuery();

                    file.CheckIn(GenUtil.SafeTrim(comment), checkinType);
                    ctx.ExecuteQuery();
                }
            }
            catch (Exception ex)
            {
                msg = SHOW_FULL_ERRORS ? ex.ToString() : ex.Message;
            }

            return(msg == "");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Checks in a file
        /// </summary>
        /// <param name="web">The web to process</param>
        /// <param name="url">The server relative url of the file to checkin</param>
        /// <param name="checkinType">The type of the checkin</param>
        /// <param name="comment">Message to be recorded with the approval</param>
        public static void CheckInFile(this Web web, string url, CheckinType checkinType, string comment)
        {
            File file = web.GetFileByServerRelativeUrl(url);
            web.Context.Load(file, x => x.Exists, x => x.CheckOutType);
            web.Context.ExecuteQuery();

            if (file.Exists)
            {
                if (file.CheckOutType != CheckOutType.None)
                {
                    file.CheckIn(comment, checkinType);
                    web.Context.ExecuteQuery();
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Checks in a file
        /// </summary>
        /// <param name="web">The web to process</param>
        /// <param name="url">The server relative url of the file to checkin</param>
        /// <param name="checkinType">The type of the checkin</param>
        /// <param name="comment">Message to be recorded with the approval</param>
        public static void CheckInFile(this Web web, string url, CheckinType checkinType, string comment)
        {
            File file = web.GetFileByServerRelativeUrl(url);

            web.Context.Load(file, x => x.Exists, x => x.CheckOutType);
            web.Context.ExecuteQueryRetry();

            if (file.Exists)
            {
                if (file.CheckOutType != CheckOutType.None)
                {
                    file.CheckIn(comment, checkinType);
                    web.Context.ExecuteQueryRetry();
                }
            }
        }
Exemplo n.º 4
0
        public void CheckIn(string comment, CheckinType checkInType)
        {
            ClientRuntimeContext context = base.Context;

            if (base.Context.ValidateOnClient && comment != null && comment.Length > 1023)
            {
                throw ClientUtility.CreateArgumentException("comment");
            }
            ClientAction query = new ClientActionInvokeMethod(this, "CheckIn", new object[]
            {
                comment,
                checkInType
            });

            context.AddQuery(query);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Checks in a file
        /// </summary>
        /// <param name="web">The web to process</param>
        /// <param name="serverRelativeUrl">The server relative url of the file to checkin</param>
        /// <param name="checkinType">The type of the checkin</param>
        /// <param name="comment">Message to be recorded with the approval</param>
        public static void CheckInFile(this Web web, string serverRelativeUrl, CheckinType checkinType, string comment)
        {
            var file = web.GetFileByServerRelativeUrl(serverRelativeUrl);

            var scope = new ConditionalScope(web.Context, () => file.ServerObjectIsNull.Value != true && file.Exists && file.CheckOutType != CheckOutType.None);

            using (scope.StartScope())
            {
                web.Context.Load(file);
            }
            web.Context.ExecuteQueryRetry();

            if (scope.TestResult.Value)
            {
                file.CheckIn(comment, checkinType);
                web.Context.ExecuteQueryRetry();
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Checks in a file
        /// </summary>
        /// <param name="web">The web to process</param>
        /// <param name="serverRelativeUrl">The server relative url of the file to checkin</param>
        /// <param name="checkinType">The type of the checkin</param>
        /// <param name="comment">Message to be recorded with the approval</param>
        public static void CheckInFile(this Web web, string serverRelativeUrl, CheckinType checkinType, string comment)
        {
            var file = web.GetFileByServerRelativeUrl(serverRelativeUrl);

            var scope = new ConditionalScope(web.Context, () => file.ServerObjectIsNull.Value != true && file.Exists && file.CheckOutType != CheckOutType.None);

            using (scope.StartScope())
            {
                web.Context.Load(file);
            }
            web.Context.ExecuteQueryRetry();

            if (scope.TestResult.Value)
            {
                file.CheckIn(comment, checkinType);
                web.Context.ExecuteQueryRetry();
            }
        }
        public static void RemoveWebPartFromPage(this ClientContext ctx, string pageServerRelativeUrl, string webPartTitle)
        {
            if (string.IsNullOrEmpty(pageServerRelativeUrl) == true)
            {
                throw new ArgumentNullException(nameof(pageServerRelativeUrl));
            }
            if (string.IsNullOrEmpty(webPartTitle) == true)
            {
                throw new ArgumentNullException(nameof(webPartTitle));
            }
            //
            var page = ctx.Web.GetFileByServerRelativeUrl(pageServerRelativeUrl); ctx.Load(page);
            var item = page.ListItemAllFields; //ctx.Load(item, _ => _.ParentList);
            var list = item.ParentList; ctx.Load(list, _ => _.ForceCheckout, _ => _.EnableVersioning, _ => _.EnableVersioning, _ => _.EnableMinorVersions, _ => _.EnableModeration);

            ctx.ExecuteQuery();
            bool        checkoutRequiredQ  = (list.ForceCheckout == true);
            CheckinType checkInType        = ((list.EnableVersioning == true) ? (list.EnableMinorVersions == true) ? CheckinType.MinorCheckIn : CheckinType.OverwriteCheckIn : CheckinType.OverwriteCheckIn);
            bool        moderationEnabledQ = (list.EnableModeration == true);
            //
            bool pageChangedQ = false, pageCheckedOutQ = false;

            try
            {
                // Check out
                if (checkoutRequiredQ == true && page.CheckOutType != CheckOutType.Online)
                {
                    page.CheckOut(); pageCheckedOutQ = true;
                }
                //
                // Gets the webparts available on the page
                var wpm = page.GetLimitedWebPartManager(PersonalizationScope.Shared);
                ctx.Load(wpm.WebParts, _ => _.Include(_2 => _2.WebPart.Title));
                ctx.ExecuteQuery();
                //
                // Check if the current webpart already exists.
                var webPartDef = wpm.WebParts.Cast <WebPartDefinition>().Where(_ => _.WebPart.Title == webPartTitle).FirstOrDefault();
                if (webPartDef != null)
                {
                    // Remove it from page
                    webPartDef.DeleteWebPart();
                    ctx.ExecuteQuery();
                    //
                    pageChangedQ = true;
                }
                //
            }
            finally
            {
                if (pageCheckedOutQ == true)
                {
                    if (pageChangedQ == true)
                    {
                        // Check in
                        page.CheckIn($@"Removed WebPart '{webPartTitle}' from the Page.", checkInType);
                    }
                    else
                    {
                        // Discard Check out
                        page.UndoCheckOut();
                    }
                }
            }
        }
        public static void AddOrUpdateWebPartToPage(this ClientContext ctx, string pageServerRelativeUrl, string webPartXml, string webPartTitle = null, string zoneId = null, int?zoneIndex = null)
        {
            if (string.IsNullOrEmpty(pageServerRelativeUrl) == true)
            {
                throw new ArgumentNullException(nameof(pageServerRelativeUrl));
            }
            if (string.IsNullOrEmpty(webPartXml) == true)
            {
                throw new ArgumentNullException(nameof(webPartXml));
            }
            //
            var page = ctx.Web.GetFileByServerRelativeUrl(pageServerRelativeUrl); ctx.Load(page);
            var item = page.ListItemAllFields; //ctx.Load(item, _ => _.ParentList);
            var list = item.ParentList; ctx.Load(list, _ => _.ForceCheckout, _ => _.EnableVersioning, _ => _.EnableVersioning, _ => _.EnableMinorVersions, _ => _.EnableModeration);

            ctx.ExecuteQuery();
            bool        checkoutRequiredQ  = (list.ForceCheckout == true);
            CheckinType checkInType        = ((list.EnableVersioning == true) ? (list.EnableMinorVersions == true) ? CheckinType.MinorCheckIn : CheckinType.OverwriteCheckIn : CheckinType.OverwriteCheckIn);
            bool        moderationEnabledQ = (list.EnableModeration == true);
            //
            bool pageChangedQ = false, pageCheckedOutQ = false;

            try
            {
                // Check out
                if (checkoutRequiredQ == true && page.CheckOutType != CheckOutType.Online)
                {
                    page.CheckOut(); pageCheckedOutQ = true;
                }
                //
                // Gets the webparts available on the page
                var wpm = page.GetLimitedWebPartManager(PersonalizationScope.Shared);
                ctx.Load(wpm.WebParts, _ => _.Include(_2 => _2.WebPart.Title));
                ctx.ExecuteQuery();
                //
                // Check if the current webpart already exists.
                var webPartDef = ((string.IsNullOrEmpty(webPartTitle) == false) ? wpm.WebParts.Cast <WebPartDefinition>().Where(_ => _.WebPart.Title == webPartTitle).FirstOrDefault() : null);
                if (webPartDef == null)
                {
                    // Import the webpart xml
                    var importedWebPartDef = wpm.ImportWebPart(webPartXml);
                    #region Try getting the Title,ZoneID,ZoneIndex from 'webPartXml'
                    string importedWebPartDefTitle     = null; try { importedWebPartDefTitle = importedWebPartDef.WebPart.Title; } catch { }
                    string importedWebPartDefZoneID    = null;
                    int?   importedWebPartDefZoneIndex = null; try { importedWebPartDefZoneIndex = importedWebPartDef.WebPart.ZoneIndex; } catch { }
                    try
                    {
                        XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(webPartXml); XmlElement xmlWebPartDef = xmlDoc.DocumentElement;
                        if (importedWebPartDefTitle == null)
                        {
                            importedWebPartDefTitle = xmlWebPartDef.SelectSingleNode(@"*[local-name()='Title']")?.InnerText;
                        }
                        if (importedWebPartDefZoneID == null)
                        {
                            importedWebPartDefZoneID = xmlWebPartDef.SelectSingleNode(@"*[local-name()='ZoneID']")?.InnerText;
                        }
                        if (importedWebPartDefZoneIndex == null)
                        {
                            var tmp = xmlWebPartDef.SelectSingleNode(@"*[local-name()='PartOrder']")?.InnerText; var tmp2 = 0; if (int.TryParse(tmp, out tmp2) == true)
                            {
                                importedWebPartDefZoneIndex = tmp2;
                            }
                        }
                    }
                    catch (Exception ex) { Logger.Warning(ex, $@"Could not parse the webPartXml to retrive the WebPart Defintion Title and ZoneId."); }
                    #endregion Try getting the Title,ZoneID,ZoneIndex from 'webPartXml'
                    //
                    webPartDef = ((string.IsNullOrEmpty(importedWebPartDefTitle) == false) ? wpm.WebParts.Cast <WebPartDefinition>().Where(_ => _.WebPart.Title == importedWebPartDefTitle).FirstOrDefault() : null);
                    if (webPartDef == null)
                    {
                        webPartDef = importedWebPartDef;
                        if (string.IsNullOrEmpty(webPartTitle) == true)
                        {
                            webPartTitle = ((string.IsNullOrEmpty(importedWebPartDefTitle) == false) ? importedWebPartDefTitle : "Untitled WebPart");
                        }                                                                                                                                                                             // try to determine the 'zoneId', when this is not provided explicitly.
                        if (string.IsNullOrEmpty(zoneId) == true)
                        {
                            zoneId = ((string.IsNullOrEmpty(importedWebPartDefZoneID) == false) ? importedWebPartDefZoneID : "wpz");
                        }                                                                                                                                                      // try to determine the 'zoneId', when this is not provided explicitly.
                        if (zoneIndex == null)
                        {
                            zoneIndex = importedWebPartDefZoneIndex ?? 0;
                        }                                                                        // try to determine the 'zoneIndex', when this is not provided explicitly.
                        //
                        // Add it to page
                        webPartDef.WebPart.Title = webPartTitle;
                        var addedWebPartDef = wpm.AddWebPart(webPartDef.WebPart, zoneId, zoneIndex ?? 0); ctx.Load(addedWebPartDef, _ => _.Id);
                        //page = ctx.Web.GetFileByServerRelativeUrl(pageServerRelativeUrl); ctx.Load(page); // re-load page file
                        item = page.ListItemAllFields; ctx.Load(item); // load page item
                        ctx.ExecuteQuery();
                        //
                        if (item != null)
                        {
                            bool itemChangedQ = false;
                            foreach (string pageFieldName in new string[] { "WikiField", "PublishingPageContent" }.Where(_ => item.FieldValues.ContainsKey(_)))
                            {
                                item[pageFieldName] += $@"

<div class=""ms-rtestate-read ms-rte-wpbox"">
    <div class=""ms-rtestate-notify  ms-rtestate-read {addedWebPartDef.Id}"" id=""div_{addedWebPartDef.Id}""></div>
    <div id=""vid_{addedWebPartDef.Id}"" style=""display:none;"">
    </div>
</div>

";
                                itemChangedQ         = true;
                            }
                            if (itemChangedQ == true)
                            {
                                item.Update();
                                ctx.ExecuteQuery();
                            }
                        }
                        //
                        pageChangedQ = true;
                    }
                }
                if (pageChangedQ == false && webPartDef != null)
                {
                    bool changedQ = false;
                    if (string.IsNullOrEmpty(webPartTitle) == false)
                    {
                        webPartDef.WebPart.Title = webPartTitle; changedQ = true;
                    }
                    //if (zoneId != null) { webPartDef.WebPart.ZoneId = zoneId ?? ""; changedQ = true; }
                    //if (zoneIndex != null) { webPartDef.WebPart.ZoneIndex = zoneIndex ?? 0; changedQ = true; }
                    if (changedQ == true)
                    {
                        // Update it on page
                        webPartDef.SaveWebPartChanges();
                        ctx.ExecuteQuery();
                        //
                        pageChangedQ = true;
                    }
                }
            }
            finally
            {
                if (pageCheckedOutQ == true)
                {
                    if (pageChangedQ == true)
                    {
                        // Check in
                        page.CheckIn($@"Added WebPart '{webPartTitle}' to the Page.", checkInType);
                    }
                    else
                    {
                        // Discard Check out
                        page.UndoCheckOut();
                    }
                }
            }
        }
Exemplo n.º 9
0
 partial void DeleteCheckinType(CheckinType instance);
Exemplo n.º 10
0
 partial void UpdateCheckinType(CheckinType instance);
Exemplo n.º 11
0
 partial void InsertCheckinType(CheckinType instance);
Exemplo n.º 12
0
 public void CheckIn(string comment, CheckinType checkinType)
 {
     _file.CheckIn(comment, checkinType);
     _file.RefreshLoad();
     _file.Context.ExecuteQuery();
 }
Exemplo n.º 13
0
 public void CheckIn(string comment, CheckinType checkinType)
 {
     _file.CheckIn(comment, checkinType);
     _file.RefreshLoad();
     _file.Context.ExecuteQuery();
 }
Exemplo n.º 14
0
        public static void CheckInFile(string url, CheckinType checkinType, string comment, Web web, ClientContext clientContext)
        {
            Microsoft.SharePoint.Client.File file = null;
            file = web.GetFileByServerRelativeUrl(url);
            clientContext.Load(file, x => x.Exists, x => x.CheckOutType);
            clientContext.ExecuteQuery();

            if (file.Exists)
            {
                if (file.CheckOutType != CheckOutType.None)
                {
                    file.CheckIn(comment, checkinType);
                    clientContext.ExecuteQuery();
                }
            }
        }