1

How can I update the published date of a node programmatically in umbraco?

Francis Benyah
  • 567
  • 7
  • 11
  • Are you asking how to actually publish a node, or just update the published date without publishing? – LoveFortyDown Mar 06 '15 at 08:55
  • Or better off just publish the page in code that wili in turn update the published date. – denford mutseriwa Mar 09 '15 at 07:14
  • Just how to update the published date of the node. The node is already published. I could successfully update the update date field in the cmsdocument table however i could not get that result to push through to the umbraco.config xml file – Francis Benyah Mar 16 '15 at 17:40

2 Answers2

0

I'm assuming the reason you're not just republishing the content, is because you want to set a specific date and not the current date?

You should be able to trigger a rebuild of the XML cache by using this function: umbraco.library.UpdateDocumentCache();

This function is however marked obsolete in later version of umbraco so without having tested it I'm not sure if it does what you need.

Claus
  • 1,975
  • 18
  • 24
0

You can programmatically update the date which a node was last edited using the ContentService.

You can usually access this service by using ApplicationContext.Current.Services.ContentService.

var content = Services.ContentService.GetById(1060);

content.UpdateDate = new DateTime(2017, 07, 14, 17, 0, 0);

Services.ContentService.Save(content);

You can also update other properties on a node by using:

content.SetValue("propertyAlias", "value");

Tested on Umbraco 7.6.1.

harvzor
  • 2,832
  • 1
  • 22
  • 40