SPListItem.UpdateOverwriteVersion Method (Microsoft.SharePoint)
Updates the item without creating another version of the item.

Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in microsoft.sharepoint.dll)
Syntax

Visual Basic (Declaration)
Public Sub UpdateOverwriteVersion
Visual Basic (Usage)
Dim instance As SPListItem

instance.UpdateOverwriteVersion
C#
public void UpdateOverwriteVersion ()
See Also

Tags :


Community Content

Michael Washam - MSFT
SPListItem.UpdateOverwriteVersion example

Description:

The SPListItem.UpdateOverwriteVersion method allows for the setting of properties on a SPListItem object without creating a separate version of the item. This method also allows for setting of certain system properties such as Created (date), Modified (date), Author and Editor.

Usage scenario:

Use when you need to update a list item without creating a separate version. This method is useful for recreation of items to an original state.

C# Code Sample

                using (SPSite sps = new SPSite("http://server/"))
{
using (SPWeb spw = sps.OpenWeb())
{
SPList spSharedDocs = spw.Lists["Shared Documents"];
SPListItem spli = spSharedDocs.Items[0];
spli["Created"] = new DateTime(2007, 1, 1);
spli["Author"] = "-1;#domain\\user";
spli["Editor"] = "-1;#domain\\user";
spli["Modified"] = new DateTime(2007, 2, 1);
spli.UpdateOverwriteVersion();
}
}



VB.NET Code Sample

              Using sps As SPSite = New SPSite("http://server")
Using spw As SPWeb = sps.OpenWeb()
Dim spSharedDocs As SPList = spw.Lists("Shared Documents")
Dim spli As SPListItem = spSharedDocs.Items(0)
spli("Created") = New DateTime(2008, 1, 1)
spli("Author") = "-1;#domain\user"
spli("Editor") = "-1;#domain\user"
spli("Modified") = New DateTime(2008, 2, 1)
spli.UpdateOverwriteVersion()
End Using
End Using




discovia
I tried the above code and it did not work... until I updated the Editor also.
Seems you need to update both the author and editor.

Running

listItem["Author"] = oUser;

will not update the author. You need to update both:

listItem["Author"] = oUser;
listItem["Editor"] = oUser;


Tags :

Page view tracker