locked
Save Conflict SharePoint 2010 error RRS feed

  • Question

  • Hi,

    Am getting the following error in SP2010 list updation.

    Save Conflict

    Your changes conflict with those made concurrently by another user. If you want your changes to be applied, click Back in your Web browser, refresh the page, and resubmit your changes.


    The following is the code I have used to update the list.


    SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    SPSite site = SPContext.Current.Site;
                    SPWeb web = SPContext.Current.Web;
                    using (SPSite newSite = new SPSite(site.ID))
                    {
                        using (SPWeb newWeb = newSite.OpenWeb(web.ID))
                        {
                            string ListName = this.WebPart.DiscussionboardListName.ToString();
                            SPList list = newWeb.Lists.TryGetList(ListName);
                            SPListItemCollection itemColl = list.GetItems(new SPQuery());
                            foreach (SPListItem fldListitem in itemColl)
                            {
                                string qnTitle = fldListitem["Title"].ToString();
                                string qnDescription = fldListitem["Post"].ToString();
                                string Question = "";
                                Question = "<b>" + qnTitle + " : "+ qnDescription + "</b>" + "<br/>";

                                int lReply = Convert.ToInt32(fldListitem["Replies"]);
                                newWeb.AllowUnsafeUpdates = true;
                                string postMsg = "";
                                string postedReply = "";
                                if (lReply > 0)
                                {
                                    SPQuery query = new SPQuery();
                                    query.Folder = fldListitem.Folder;
                                    SPListItemCollection itemscol = list.GetItems(query);

                                    foreach (SPListItem liItem in itemscol)
                                    {
                                        if(liItem["TrimmedBody"] != null)
                                            postedReply = liItem["TrimmedBody"].ToString();                                                                        
                                    }
                                }

                                string completePost = Question + postedReply;
                                string customFieldName = "Questions";
                                
                                fldListitem[customFieldName] = HttpUtility.HtmlDecode(completePost).ToString();
                                fldListitem.Update();
                                newWeb.AllowUnsafeUpdates = false;
                            }
                        }
                    }
                });

    Please let me know how to solve this.

    Friday, February 13, 2015 7:32 AM

Answers

All replies

  • Hi :

     SPSite site = SPContext.Current.Site;
     SPWeb web = SPContext.Current.Web;

    Use this just above the run with elevated privileges and give try.

    And where have you written this code.like in feature or webpart?

    and also try to declare 

     newWeb.AllowUnsafeUpdates = true;

    and 

     newWeb.AllowUnsafeUpdates = false;

    outside for loop.



    Regards, Rajendra Singh If a post answers your question, please click Mark As Answer on that ost and Vote as Helpful http://sharepointundefind.wordpress.com/



    Friday, February 13, 2015 10:44 AM
  • Thanks for your reply. I will try as per your suggestion.

    I have written this code in the Webpart.

    Friday, February 13, 2015 10:57 AM
  • I tried as per your suggestion but still i am facing the issue.
    Friday, February 13, 2015 11:23 AM
  • can u please let met know on which line u r getting the issue using debugger.

    Or

    you can share whole webpart code as to see where you have written.i hope this wont be there in render webpart method


    Regards,

    Rajendra Singh If a post answers your question, please click Mark As Answer on that post and Vote as Helpful http://sharepointundefind.wordpress.com/


    Friday, February 13, 2015 11:27 AM
  • This is the complete code I have written in the web part ascx.cs file.


    using System;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.Utilities;
    using System.Web;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Text.RegularExpressions;

    namespace CustomDiscussionWP.CustomDiscussion
    {
        public partial class CustomDiscussionUserControl : UserControl
        {
            public CustomDiscussion WebPart { get; set; }
            
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!string.IsNullOrEmpty(this.WebPart.DiscussionboardListName))
                {
                    SetPostwithReply();                
                }
            }

            public void SetPostwithReply()
            {
                SPSite site = SPContext.Current.Site;
                SPWeb web = SPContext.Current.Web;
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {                
                    using (SPSite newSite = new SPSite(site.ID))
                    {
                        using (SPWeb newWeb = newSite.OpenWeb(web.ID))
                        {
                            string ListName = this.WebPart.DiscussionboardListName.ToString();
                            SPList list = newWeb.Lists.TryGetList(ListName);
                            SPListItemCollection itemColl = list.GetItems(new SPQuery());
                            newWeb.AllowUnsafeUpdates = true;
                            foreach (SPListItem fldListitem in itemColl)
                            {
                                string qnTitle = fldListitem["Title"].ToString();
                                string qnDescription = fldListitem["Post"].ToString();
                                string Question = "";
                                Question = "<b>" + qnTitle + " : "+ qnDescription + "</b>" + "<br/>";
                                int lReply = Convert.ToInt32(fldListitem["Replies"]);                            
                                string postMsg = "";
                                string postedReply = "";
                                if (lReply > 0)
                                {
                                    SPQuery query = new SPQuery();
                                    query.Folder = fldListitem.Folder;
                                    SPListItemCollection itemscol = list.GetItems(query);

                                    foreach (SPListItem liItem in itemscol)
                                    {
                                        if(liItem["TrimmedBody"] != null)
                                            postedReply = liItem["TrimmedBody"].ToString();                                                                        
                                    }
                                }

                                string completePost = Question + postedReply;
                                string customFieldName = "Questions";
                                
                                fldListitem[customFieldName] = HttpUtility.HtmlDecode(completePost).ToString();
                                fldListitem.Update();                            
                            }
                            newWeb.AllowUnsafeUpdates = false;
                        }
                    }
                });
            }
        }
    }

    Am getting this error only when multiple users are accessing the site at the same time.


    Friday, February 13, 2015 12:40 PM
  • Hi

    can you tell me your exact requirement as what you want to achieve?

    as per the above code u have created a webpart and place in the user control. SetPostwithReply() should be called in the some other event as the control always load when ever page load.thats why its giving the error.


    Regards, Rajendra Singh If a post answers your question, please click Mark As Answer on that ost and Vote as Helpful http://sharepointundefind.wordpress.com/

    Friday, February 13, 2015 3:19 PM
  • Hi

    I have a discussion board consisting with some posts and replies.
    As per the normal SharePoint behavior the replies can be viewed by clicking on the post only (as far as I know).
    But I want to show the all Post and it's related replies one after the other on page load itself.
    This is the reason I have created a web part and iterating through each post and reply, to display in the desired format.

    Monday, February 16, 2015 7:25 AM
  • see below link for your reference 

    http://www.sharepointbreak.com/2012/10/28/sharepoint-2010-ootb-note-board-web-part-in-library-item-display-form/

    and why r u updating Question Column.

     fldListitem[customFieldName] = HttpUtility.HtmlDecode(completePost).ToString();
      fldListitem.Update();



    Regards,

    Rajendra Singh

    If a post answers your question, please click Mark As Answer on that ost and Vote as Helpful http://sharepointundefind.wordpress.com/



    Tuesday, February 17, 2015 7:28 AM