How to use item.SystemUpdate() in SharePoint

item.SystemUpdate() - It is used when we do not want fields such as Modified,ModifiedBy gets updated or if we do not want a new version should be created.
 
In the below code I used to get SharePoint List Item from different method and then update it.
  1. using (SPSite site = new SPSite(SPContext.Current.Site.ID))  
  2.   
  3. {  
  4.   
  5. using (SPWeb web = site.OpenWeb())  
  6.   
  7. {  
  8.   
  9. SPListItem item = GetItem("TestListSite1", 1);  
  10.   
  11. web.AllowUnsafeUpdates = true;  
  12.   
  13. item["Title"] = "Update List Item";  
  14.   
  15. item.SystemUpdate();  
  16.   
  17. web.AllowUnsafeUpdates = false;  
  18.   
  19. //remaining code  
  20.   
  21. }  
  22.   
  23. }  
Executing the above code gave an error below.
 
 
After searching I found that we should make AllowUnsafeUpdates = true of the item that we are updating and since I was getting item from a different method I used the below code.
 
The only change I made is this item.Web.AllowUnsafeUpdates = true;
  1. using (SPSite site = new SPSite(SPContext.Current.Site.ID))  
  2.   
  3. {  
  4.   
  5. using (SPWeb web = site.OpenWeb())  
  6.   
  7. {  
  8.   
  9. SPListItem item = GetItem("TestListSite1", 1);  
  10.   
  11. item.Web.AllowUnsafeUpdates = true;  
  12.   
  13. item["Title"] = "Update List Item";  
  14.   
  15. item.SystemUpdate();  
  16.   
  17. item.Web.AllowUnsafeUpdates = false;  
  18.   
  19. }  
  20.   
  21. }  
By using above code I was successfully able to update the list item using item.SystemUpdate();