16 July 2015

umbraco set date field value from code

Had problems with umbraco not setting date field value from code, when you reloaded the interface.

My conversion code was:

var content = contentService.GetById(3150);
//content.SetValue("publicationDate", dateValue);
content.Properties["publicationDate"].Value = dateValue;
contentService.SaveAndPublishWithStatus(content, raiseEvents: true);

Notice both formats for entering values is usable. 
The resulting data was that the value was being written to the database in the date field

SELECT TOP 1000 *
  FROM [Umbraco].[dbo].[cmsPropertyData] where contentNodeId like '3150'

When dealing with a date field that has a prior value you can see the changed value right away when refreshing the browser, when working with an empty date you have to recycle the apppool for the date to come up in the interface. 


1 comment:

Casper6060 said...

This was something i had been looking for, for a day or 2 now, thanks a lot

i tried using the SetValue when i updated the field but with no luck, but the Properties["alias"].Value worked brilliantly