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.
View Comments (15)
Hello all,
Thanks for valuable information. I was also trying to find the solution of this problem.
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.
Try to change modified date too before SystemUpdate().
Be aware that if also change the Modified date, the Alerts will trigger (if you use them in your solution).
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..
I don't suppose you got this working with the Author field? It won't work for me...
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.
Thank u so much.
Valueable information. what about the user if we don't want to change on updation?
Kuldeep Kadyan
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
Hi, Samit!
You don't need List.Update() as you don't change properties of list.
Thanks for this article, it has been very useful.
this is code to delete item on gridview sharepoint
protected void btDelete_Click(object sender, EventArgs e)
{
SPWeb web = SPContext.Current.Web;
SPList list = web.Lists["ListEmployee"];
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox checkstatus = (CheckBox)row.FindControl("checkItem");
if ( checkstatus.Checked == true )
{
TextBox txtID = new TextBox();
txtID.Text = GridView1.DataKeys[row.RowIndex].Value.ToString();
list.GetItemById(Convert.ToInt32(txtID.Text)).Delete();
list.Update();
}
}
GridView1.EditIndex = -1;
BindtoGridview();
}
Can somebody pelase tell me how to do this with the Client OM
Hi Graham,
I don't think this is possible using Client OM.
In Client OM, for ListItem, only Update() is present to update the item and it always increases version if versioning is enabled in the list.
Hi Graham,
Thank you very much, this is solving my problem on SharePoint 2010 too.