How to set the creator or writer of a content item in a controller action
Hello,
I have started using Umbraco one month ago and I learned so much thanks to Umbraco.tv and Umbraco courses.
In my project I created a custom dashboard. This dashboard makes it possible for writers to write a message about what they are going to write.
When creating a content item I would like to save who made the content item.
Currently I do this by saving the userId in a custom property because WriterId and CreatorId don't seem to work.
[System.Web.Http.HttpPost]
public HttpResponseMessage CreateMessage(Message message)
{
var contentService = Services.ContentService;
int userId = UmbracoUser.Id;
var newMessage = Services.ContentService.CreateContent(message.Content, 1117, "message");
newMessage.SetValue("content", message.Content);
newMessage.SetValue("userId", userId);
//newMessage.WriterId = userId; does not work,always saves a 0
//newMessage.CreatorId = userId; does not work,always saves a 0
contentService.Save(newMessage);
contentService.PublishWithStatus(newMessage);
return new HttpResponseMessage(System.Net.HttpStatusCode.OK);
}
Any suggestions on how I could set the creator of a content item without using a custom property?
The next and final step for setting up Umbraco as my CMS for my magazine website is importing all the articles from my custom made CMS.
So creating a content item from a controller will always set the creator to user with id 0 even when logged in with a different user and the creation date to the current date.
So that means I will have to make custom properties for userId and creationTime and make a custom dashboard so content writers can edit posts that they made in the old CMS.
Should have explored those functions before asking :p.
Seems like it is also possible to change the createDate if it is set between saving the content and publishing it.
If you set the value before the save it won't work.
Haven't found a way yet to make the updateDate save but that is a known issue (http://issues.umbraco.org/issue/U4-4800)
:)
while copying content, the creatorId is set to 0. I tried but none of these funtions helps
contentService.Save(newMessage, userId);
contentService.PublishWithStatus(newMessage, userId);
Any idea if its possible to change value of creatorId while copying?
How to set the creator or writer of a content item in a controller action
Hello,
I have started using Umbraco one month ago and I learned so much thanks to Umbraco.tv and Umbraco courses.
In my project I created a custom dashboard. This dashboard makes it possible for writers to write a message about what they are going to write.
When creating a content item I would like to save who made the content item. Currently I do this by saving the userId in a custom property because WriterId and CreatorId don't seem to work.
Any suggestions on how I could set the creator of a content item without using a custom property?
Regards, Nicola Nauwynck
Hi Nicola,
It's not possible, same for create and update date. Umbraco will always set the values.
Best,
Richard
Hmmm
The next and final step for setting up Umbraco as my CMS for my magazine website is importing all the articles from my custom made CMS.
So creating a content item from a controller will always set the creator to user with id 0 even when logged in with a different user and the creation date to the current date.
So that means I will have to make custom properties for userId and creationTime and make a custom dashboard so content writers can edit posts that they made in the old CMS.
for creation date and update date i assume this is the wanted behavior. but for the writerId and creatorId it isnt.
if you are logged in as user 10 it should save 10, not 0.
You should be able to set the creator Id by using the overload of CreateContent that takes a User Id as the last parameter:
After saving the content the writerId is set to 0. The writerId was set to 1 with the overload method but it changed to 0 after the save.
The Save and Publish methods also have overloads where you can set the UserId, so try setting those:
Good. With these
you can retreive the name of the backoffice user.
Haha that did the trick :).
Should have explored those functions before asking :p.
Seems like it is also possible to change the createDate if it is set between saving the content and publishing it. If you set the value before the save it won't work.
Haven't found a way yet to make the updateDate save but that is a known issue (http://issues.umbraco.org/issue/U4-4800) :)
Ah of course true you can set the user... It's not a property
while copying content, the creatorId is set to 0. I tried but none of these funtions helps contentService.Save(newMessage, userId); contentService.PublishWithStatus(newMessage, userId);
Any idea if its possible to change value of creatorId while copying?
is working on a reply...