Set DateTime in ItemAdding/ItemAdded
-
Tuesday, September 30, 2008 4:09 PMWhen trying to set a date field's value in an event receiver I get the following error (from the SP log file). How should I be setting the date field's value?
Field in List Definition:
<Field ID="{...}"
Name="DateField"
Type="DateTime"
Format="DateTime"
StorageTZ="UTC"
DisplayName="Date Field"
Description="..."
SourceID="http://schemas.microsoft.com/sharepoint/v3"
Required="FALSE"/>
ItemAdding() snippet:
properties.AfterProperties[fields["Date Field"].InternalName] = SPUtility.CreateISO8601DateTimeFromSystemDateTime(DateTime.Now).ToString();
A trace of what SPUtility returns:
2008-09-30T10:53:28Z
Error in log:
Error loading and running event receiver <...>.<...>ListItemHandler in <...>, Version=1.0.0.0, Culture=neutral, PublicKeyToken=<...>. Additional information is below. : Value does not fall within the expected range.
Answers
-
Tuesday, September 30, 2008 7:08 PM
You're setting your property as a string it should be set as Date Time.
Hope it helps,
Rafael- Proposed As Answer by Rafael Mascarenhas Friday, October 03, 2008 2:53 PM
- Marked As Answer by Michael Washam - MSFT Wednesday, October 22, 2008 3:19 PM
All Replies
-
Tuesday, September 30, 2008 6:14 PMIt looks right.. Add a breakpoint in your ItemAdding event.
Then add:
properties.AfterProperties["Date Field"]
and
fields["Date Field"].InternalName
to your watch list to see which one is broken.
Posting is provided "AS IS" with no warranties, and confers no rights. -
Tuesday, September 30, 2008 7:08 PM
You're setting your property as a string it should be set as Date Time.
Hope it helps,
Rafael- Proposed As Answer by Rafael Mascarenhas Friday, October 03, 2008 2:53 PM
- Marked As Answer by Michael Washam - MSFT Wednesday, October 22, 2008 3:19 PM

