Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
SDK Documentation
SPListItem Class
SPListItem Methods
 UpdateOverwriteVersion Method

  Switch on low bandwidth view
Community Content
In this section
Statistics Annotations (0)
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)
Visual Basic (Declaration)
Public Sub UpdateOverwriteVersion
Visual Basic (Usage)
Dim instance As SPListItem

instance.UpdateOverwriteVersion
C#
public void UpdateOverwriteVersion ()
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
SPListItem.UpdateOverwriteVersion example      Michael Washam - MSFT   |   Edit   |   Show History

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



I tried the above code and it did not work... until I updated the Editor also.      discovia   |   Edit   |   Show History
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 What's this?: Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker