5

Here's an odd one:

I have a content type derived from SPFolder, that I am creating through code. As part of the creation process, I am trying to set the "Created By" information to be the user who should be attributed as the creator of the folder. I'm using the following code:

// after setting some other field values:

SPFieldUserValue userValue = new SPFieldUserValue(web, user.ID, user.LoginName);
folderItem[SPBuiltInFieldId.Author] = userValue;
folderItem[SPBuiltInFieldId.Created_x0020_By] = userValue;
folderItem.SystemUpdate(false);

Now, if I go in with Powershell or SharePoint Manager, I can see that in the folder's properties and in the folder's item's properties, the value of vti_author and display_urn:schemas-microsoft-com:office:office#Author is the correct user value, and the only place I can find SHAREPOINT\system is in vti_modifiedby.

However, when I go and view properties of the folder (through the SharePoint UI), in the view form, the System Account is listed for both created by and modified by. And, if I add "Created By" to the list view, it's all System Account there too.

So where is SharePoint pulling that from? What other mystery field do I need to set to get my user as the Created By person?

  • Have you tried setting the Author field to just an SPUser object. I have done this before and that worked. – spevilgenius Apr 5 '14 at 9:58
  • @spevilgenius, thanks for the suggestion, but that did not work. Using an SPUser object still ends up showing created by System Account in both view form and list view. – Dylan Cristy Apr 7 '14 at 14:18
  • 2
    Impersonate as that user and create folder under his account. That should do the trick. Code sample:sharepointdeveloperhq.com/2009/04/… – luccio Apr 11 '14 at 8:14
1

If you want to manipulate the system properties (author, editor, ...) you'll have to use SPListItem.UpdateOverwriteVersion()

SPListItem item = ...; 
item["Created By"] = web.EnsureUser("luisb").ID; 
item["Modified By"] = item["Modified By"]; 
item["Created"] = DateTime.Now.AddYears(-3); 
item["Modified"] = DateTime.Parse("01/01/2000"); 
item.UpdateOverwriteVersion();

See this post: http://www.sharepointblogs.be/blogs/vandest/archive/2009/04/13/sharepoint-2007-update-system-properties-created-created-by-modified-modified-by.aspx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.