none
Unable to update Modified (datetime) field using CSOM/SystemUpdate? RRS feed

  • Question

  • Greetings,

    A colleague and I are working on a small application to migrate some of our SharePoint files to SharePoint 365 while preserving certain desired metadata. Using the following function, we want to be able to preserve the Modified field when we bring the new file over, setting it to what it was previously rather than the point in time during which the file was moved to the 365 site. Quick note: we're using the latest CSOM nuget package to execute these calls. (See code below):

    Function ChangeFileProps(DestSiteURL As String, destDocLibrary As String, FilePath As String)

            Try

                Dim LocalFileURL, DestFileURL As String

                Dim relativePath As String

                Dim passWordSecure As SecureString = ConvertToSecureString(DestinationPWD)

                Dim url As String = DestSiteURL

                Using context = New ClientContext(url)

                    context.Credentials = New SharePointOnlineCredentials(DestinationUsername, passWordSecure)

                    context.Load(context.Web, Function(w) w.Title)

                    context.ExecuteQuery()

                    Dim docs As List = context.Web.Lists.GetByTitle(destDocLibrary)

                    context.Load(docs, Function(l) l.RootFolder)

                    ' Get the information about the folder that will hold the file

                    context.Load(docs.RootFolder, Function(f) f.ServerRelativeUrl)

                    context.ExecuteQuery()

                    relativePath = docs.RootFolder.ServerRelativeUrl.ToString

                    DestFileURL = relativePath + "/" + Replace(FilePath, "\", "/")

                    Dim uploadedFile = context.Web.GetFileByServerRelativeUrl(DestFileURL)

                    context.Load(uploadedFile, Function(f) f.ListItemAllFields)

                    context.ExecuteQuery()

                    'Print List Item Id

                    Dim ID As String = uploadedFile.ListItemAllFields.Id

                    'uploadedFile.CheckOut()

                    Dim listItem = uploadedFile.ListItemAllFields

                    listItem("Customer_x0020_Name") = "125zzxczxc678"

                    'listItem("Modified_x0020_By") =

                    'listItem("Modified") = DateTime.Now.AddMonths(-6)

                    listItem("Modified") = "2015-07-01T05:20:00"

                    listItem.SystemUpdate()

                    'uploadedFile.CheckIn(String.Empty, CheckinType.OverwriteCheckIn)

                    context.ExecuteQuery()

                End Using

            Catch ex As Exception

            End Try

        End Function

    Currently, everything is working properly save for the modified date field. No matter what we've tried the Modified field is set to the date and time the query is executed. Any help on what we are doing wrong would be greatly appreciated.

    Wednesday, January 25, 2017 4:38 PM

Answers

  • Thank you all for the responses and suggestions thus far. As it turns out we just figured out the problem. This doeswork in SharePoint 365, but you must have Site Collection Admin privileges in order to change the Modify/Created field data. We were initially just in the Site Owners group.

    This wasn't very clear based on what we were seeing, but that was the solution for us. Hope this helps anyone else running into this.

    • Marked as answer by AKinNEPA Thursday, January 26, 2017 8:04 PM
    Thursday, January 26, 2017 8:04 PM

All replies

  • Hi,

    Please try to replace

    listItem.SystemUpdate()

    with

    listItem.UpdateOverwriteVersion()

    Or check the article below:

    Update SharePoint Online System Fields via CSOM

    https://threewill.com/update-sharepoint-online-system-fields-via-csom/

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Thursday, January 26, 2017 8:32 AM
    Moderator
  • Hi 

    SystemUpdate is only supported in server side object model and is not available in office 365. 

    Have you tried listItem.Update(), let me know if it works.

    https://threewill.com/update-sharepoint-online-system-fields-via-csom/


    Please remember to mark the replies as answers and upvote them if they help. Thanks & Regards, Balu
    Thursday, January 26, 2017 9:03 AM
  • Thank you all for the responses and suggestions thus far. As it turns out we just figured out the problem. This doeswork in SharePoint 365, but you must have Site Collection Admin privileges in order to change the Modify/Created field data. We were initially just in the Site Owners group.

    This wasn't very clear based on what we were seeing, but that was the solution for us. Hope this helps anyone else running into this.

    • Marked as answer by AKinNEPA Thursday, January 26, 2017 8:04 PM
    Thursday, January 26, 2017 8:04 PM
  • Hi,

    Thanks for sharing!

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Friday, January 27, 2017 1:43 AM
    Moderator