Export (0) Print
Expand All

SPListItem.SystemUpdate method

Updates the database with changes made to the list item without changing the Modified or Modified By fields.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

public void SystemUpdate()

When you call the SystemUpdate method, events are triggered and the modifications are reported in the Change and Audit logs, but alerts are not sent and properties are not demoted into documents.

Calling this method is the same as calling SystemUpdate(Boolean) with false.

The following example is a console application that uses the SystemUpdate method to make changes to a list item.

using System;
using Microsoft.SharePoint;

namespace Test
{
   class ConsoleApp
   {
      static void Main(string[] args)
      {
         using (SPSite site = new SPSite("http://localhost"))
         {
            using (SPWeb web = site.OpenWeb())
            {
               SPList list = web.GetList("/lists/announcements/");
               if (list.ItemCount > 0)
               {
                  // Get an item to modify.
                  SPListItem item = list.Items[0];

                  // Report the current state of the item.
                  ReportState("Before", item);

                  // Modify it.
                  if (item.HasUniqueRoleAssignments)
                     item.ResetRoleInheritance();
                  else
                     item.BreakRoleInheritance(true);

                  // Update without changing the modified time.
                  item.SystemUpdate();

                  // Report the new state of the item.
                  ReportState("After", item);
               }
            }
         }
         Console.ReadLine();
      }

      static void ReportState(string state, SPListItem item)
      {
         Console.WriteLine(state);
         Console.WriteLine("HasUniqueRoleAssigments: {0}", item.HasUniqueRoleAssignments);
         Console.WriteLine("Modified: {0}", item[SPBuiltInFieldId.Modified]);
         if (item.Fields.ContainsField("Modified_x0020_By"))
            Console.WriteLine("Modified by: {0}", item[SPBuiltInFieldId.Modified_x0020_By]);
         Console.WriteLine();
      }

   }
}
Show:
© 2014 Microsoft