Gunnar Peipman's ASP.NET blog

ASP.NET, C#, SharePoint, SQL Server and general software development topics.

Sponsors

News

 
 
 
 
 
Programming Blogs - Blog Catalog Blog Directory
 
 
 

Links

Social

How to Update SharePoint List Items without Creating New Versions

Migrating data from SP2001 to MOSS2007 is fun - if you know what I mean. During migration we discovered that migration tool has some serious bugs. I wrote some code that fixes some problems after importing process. There I found a problem - I needed to update list items without getting new versions of them after updates. Usually we see samples like this in internet:


SPList list = web.Lists["myList"];
SPListItem item = list.Items[0];

item["myField"] = "my value";

item.Update();
list.Update();


This code works perfect for end-user scenarios. It creates automatically new version of list item as Update method is called. I needed no new versions and there fore this solution wasn't great help for me. I found list item's method SystemUpdate. The following code is same as the previous one but instead of Update it uses SystemUpdate. 


SPList list = web.Lists["myList"];
SPListItem item = list.Items[0];

item["myField"] = "my value";

item.SystemUpdate(false);
list.Update();


SystemUpdate method avoids SharePoint 2007 to change modified date and modifier fields. Argument false tells that no new versions are expected. SystemUpdate solved my problem perfectly well.

Posted: Mar 23 2008, 03:14 AM by DigiMortal | with 16 comment(s)
Filed under:

Comments

??ghyBlog » links for 2008-03-23 said:

Pingback from  ??ghyBlog » links for 2008-03-23

# March 23, 2008 6:19 PM

Atul Dongare said:

Hello all,

Thanks for valuable information. I was also trying to find the solution of this problem.

# March 24, 2008 7:03 AM

JW said:

Thanks for the info.  Any idea if there is a way to mark the item as dirty so it will be picked up by an incramental crawl in search?  SystemUpdate works great but the changes aren't being reflected in search until a full crawl is done.

# March 31, 2008 10:15 AM

DigiMortal said:

Try to change modified date too before SystemUpdate().

# April 2, 2008 8:06 PM

Frank-Ove said:

Be aware that if also change the Modified date, the Alerts will trigger (if you use them in your solution).

# May 23, 2008 3:36 AM

sandeep said:

I want to touch the item in a list to be able to fire alerts ( for the subscribed items ) .. I am not getting alerts ( i am not using SystemUpdate() ) .. but when I update the item manually i get the update alert .. strange..

# August 8, 2008 2:07 PM

Donald said:

I don't suppose you got this working with the Author field?  It won't work for me...

# January 6, 2009 12:45 PM

DigiMortal said:

Author field has wider problems. I have seen Author field problems also when exporting/importing sites content. I don't think this problem lies here. It must be something more serious.

# January 6, 2009 5:45 PM

Andreas Grabner said:

You want to be careful with update performance - especially when you want to update multiple items at once. then its better to go with batch updates

Check out my research on SharePoint batch update performance @ blog.dynatrace.com/.../sharepoint-using-batch-updates-to-speed-up-performance

hope it helps

# January 26, 2009 4:09 PM

Gunnar Peipman's ASP.NET blog said:

A little mystery when updating publishing pages: page is checked out, some attributes are changed and

# May 10, 2009 9:00 AM

Akbar said:

Thanks a lot for the suggestion, it helped me in disabling 'the task has changed alert' mail to the Assigned person while using a workflow.

# June 4, 2009 4:41 AM

Update SharePoint List Items without change Modified date « Huynhvothinh's Weblog said:

Pingback from  Update SharePoint List Items without change Modified date « Huynhvothinh's Weblog

# August 5, 2009 5:31 AM

Kuldeep Kadyan said:

Thank u so much.

Valueable information. what about the user if we don't want to change on updation?

Kuldeep Kadyan

# November 5, 2009 5:04 AM

Samit said:

Hi,

After reading above article i am confused.When ever we update the list item, Is it require to call ListItem.Update() as well as List.Update()?

I think for update/delete/insert we do need to call ListItem.Update. For Insert/delete/update field(coulmn) we need to call List.Update().

Please let me know is above statment is correct or not?

Thanks,

Samit

# November 16, 2009 12:55 AM

DigiMortal said:

Hi, Samit!

You don't need List.Update() as you don't change properties of list.

# November 16, 2009 6:15 AM

Alexandros said:

Thanks!!!!!

# November 18, 2009 3:13 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)