Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

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

$
0
0

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(DestSiteURLAsString, destDocLibraryAsString, FilePathAsString)

       Try

           DimLocalFileURL, DestFileURLAsString

           Dim relativePathAsString

           Dim passWordSecureAsSecureString = ConvertToSecureString(DestinationPWD)

           Dim urlAsString = DestSiteURL

           Using context =NewClientContext(url)

                context.Credentials =NewSharePointOnlineCredentials(DestinationUsername, passWordSecure)

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

                context.ExecuteQuery()

               Dim docsAsList = 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

               DimIDAsString = 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()

           EndUsing

       Catch exAsException

       EndTry

   EndFunction

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.


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>