Try our conversational search powered by Generative AI!

Set PageCreatedBy programmatically

Vote:
 

Hello

I'm doing a custom import script that imports a number of pages by creating them programmatically, and I want to manually set the createdby username.

I have tried setting the property before saving and publishing, I have tried attaching to the various events, but no matter how I try it is allways changed to the username I'm currently logged in as.

Does anyone have a suggestion, or is this not possible?

#122850
Jun 16, 2015 16:34
Vote:
 

You can always impersonate the user you want something like this could work:

PrincipalInfo.CurrentPrincipal = new GenericPrincipal(
		new GenericIdentity("the_user_you_want"), 
		new[] { "Administrators" }
	);

Let me know how it goes...

David

#122851
Edited, Jun 16, 2015 16:37
Vote:
 

Hello

Thanks, that's a good suggestion!

#122859
Jun 16, 2015 17:14
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.