| Nick's profileSharePoint DevelopmentBlogListsNetwork | Help |
|
|
August 31 Change Document Library Created By and Modified By fieldsAfter a solid week of banging my head off my desk, I have finally mashed up a way to programmatically assign the Created By and Modified By fields in a SharePoint Document Library. In my previous post, I mentioned moving a file from one Document Library to a newly created Document Library in a separate Site Collection. That is all well and good. Inserting the document worked perfectly, except for the fact that Created By and Modified By were both ‘System Account’. This was not a proper solution. The correct result would be the originator of the workflow’s LoginName being assigned to those columns. In the end, I realized that simply using RootFolder.Files.Add() meant that the Created By and Modified By fields were Read-Only. After some more forum trolling I was able to mash up a method that took SPUser (the originator) of the workflow and pop their LoginName into both of those fields. I ended up having to use the SPFileCollection object and after obtaining the newly created file, I had to edit the Item of that File. The method is shown below: Using objFolder.Files.Add(strFiletoUpload, contents, userCreatedBy, userModifiedBy, timeCreated, timeModified) would throw an error due to Created By and Modified By being Read-Only at the time of insert. Modifying the item of the file after the insert proved to be the right solution. Don’t forget to update the item! TrackbacksThe trackback URL for this entry is: http://customsharepoint.spaces.live.com/blog/cns!41D760DBB8E4E638!188.trak Weblogs that reference this entry
|
|
|