开发者

How to set a SPFieldDateTime's value?

开发者 https://www.devze.com 2022-12-12 11:57 出处:网络
I\'m trying to duplicate a SPFieldDateTime\'s value into another SPFieldDateTime in an event handler and I have to admit, I\'m stumped.There are no obvious fields I can set in an SPFieldDatetime and t

I'm trying to duplicate a SPFieldDateTime's value into another SPFieldDateTime in an event handler and I have to admit, I'm stumped. There are no obvious fields I can set in an SPFieldDatetime and the following doesn't change my field's value:

{
   SPListItem task = (SPListItem) properties;
   task[/* destination field's guid */] = task[/* source field's guid */];
}

The code seems to be able to retrieve the fields without error. Using either of the GUIDs in SPFieldDateTime time = (SPFieldDateTime)task.Fields[/* either GUID */]; executes without error and the debugger appears to have the right field: the proper values exist开发者_StackOverflow in the properties etc.

How do I set a SPFieldDateTime value?


The failure in the above is that I did not call Update in this execution sequence. I did call update on the task but it is done in a privileged execution area which is isolated from the space the event handler runs in.

The fix:

{
   SPListItem task = (SPListItem) properties;
   task[/* destination field's guid */] = task[/* source field's guid */];
   task.Update();
}
0

精彩评论

暂无评论...
验证码 换一张
取 消