0
votes

I'm trying to change the CreateDateTime for a node/document, but it doesn't appear to be having any effect. This is what I'm trying to far:

dynamic node = new DynamicNode(1065);                     
Document n = new Document(node.Id);
n.CreateDateTime = node.articlePublishedDate;
n.Save();
n.Publish(new umbraco.BusinessLogic.User(0));
umbraco.library.UpdateDocumentCache(n.Id);  

Am I going about this in the right way? And also, am I correct in assuming that it can even be changed? The API seems to suggest the CreateDateTime has get/set, so it should work? Running the code through with breakpoints, it updates the CreateDateTime, but something with the save/publish seems to revert it back?

1
What version of umbraco is this? - Morten OC
@MortenOC this is Umbraco 7.1.8. - edparry

1 Answers

3
votes

Your code is deprecated, so you need to use the "new" ContentService in umbraco: https://our.umbraco.org/documentation/Reference/Management-v6/Services/ContentService

It should be something like this:

var cs = Services.ContentService;
var node = cs.GetById(1065);
node.CreateDate = DateTime.Now;
cs.SaveAndPublish(node);