API
Version 7.x > API > Assign LastModified or PublishFrom date View modes: 
User avatar
Member
Member
dan-moov2 - 11/28/2012 1:15:08 PM
   
Assign LastModified or PublishFrom date
We're migrating content from an existing CMS to Kentico using the API. We need to be able to carry over the last modified date but these properties all seem to be read-only. When creating a new document via the API how can we specify a lastmodified date other than the current date/time it defaults to?

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 12/3/2012 1:20:41 PM
   
RE:Assign LastModified or PublishFrom date
Hi,

Have you tried getting that particular object instance and call the SetValue method? For example:
node.SetValue("columnName", value);

In this case the column name would be DocumentModifiedWhen.

Best regards,
Juraj Ondrus

User avatar
Member
Member
dan-moov2 - 12/6/2012 5:14:48 AM
   
RE:Assign LastModified or PublishFrom date
node.SetValue("DocumentModifiedWhen", value);

Yes we've tried that doesn't work I'm afraid, it just defaults to the current datetime :(

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 12/6/2012 5:38:40 AM
   
RE:Assign LastModified or PublishFrom date
Hi,

This code is working just fine for me:
  // Create an instance of the Tree provider first
TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);

// Get the document
TreeNode node = tree.SelectSingleNode(CMSContext.CurrentSiteName, "/home", "en-us");

DateTime date = DateTime.Now;
node.SetValue("DocumentModifiedWhen", date);
node.Update();

What is your code like?

Best regards,
Juraj Ondrus

User avatar
Member
Member
dan-moov2 - 12/6/2012 5:49:30 AM
   
RE:Assign LastModified or PublishFrom date
Ours is during the creation of the node, I'm guessing we will we have to create then retrieve then update to be able to override this behaviour?

User avatar
Member
Member
dan-moov2 - 12/6/2012 5:52:10 AM
   
RE:Assign LastModified or PublishFrom date
Also, you're setting the time to DateTime.Now which is the default behaviour, are you able to set it to a previous date?
//e.g...
DateTime date = new Date(2010, 01, 01);

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 12/6/2012 6:35:57 AM
   
RE:Assign LastModified or PublishFrom date
Hi,

OK, I got it :-)

you need to set the TreeProvider.UpdateTimeStamps to false before setting the value. you can do it e.g. like this:

using(var ctx = new CMSActionContext())
{
ctx.UpdateTimeStamp = false;

// DO the magic here
}


Best regards,
Juraj Ondrus