Tuesday, April 15, 2014

Update: How to SharePoint 2013 resolve saving conflict when updating item in Discussion Board

If you are developer and try to update something in the list/site, you will get the error sometime lile this:

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

However, SharePoint 2013 has been fixed this issue by using loop statement to save again. Try 5 times to avoid the conflict saving data.
using (new SPMonitoredScope(string.Format(CultureInfo.InvariantCulture, "HandleSaveConflict for method: {0}", new object[] { action.Method.Name })))
    {
        int num = 0;
        while (num < 5)
        {
            try
            {
                action();
                return;
            }
            catch (SPException exception)
            {
                ULS.SendTraceTag(0x220191, ULSCat.msoulscat_WSS_General, ULSTraceLevel.Verbose, "Save conflict in Discussion update: " + exception.Message);
                if ((num == 5) || !SPUtility.IsSaveConflictException(exception))
                {
                    throw;
                }
                Thread.Sleep(100);
                num++;
                continue;
            }
        }
    }

That's s cute and funny. But that's fine. Learn from #Microsoft #SharePoint team to update the list somehow. Like it!

No comments: