• Upgrade your Internet Experience
  • Sign in
  • Microsoft.com
  • United States (English)
    Brasil (Português)Česká republika (Čeština)Deutschland (Deutsch)España (Español)France (Français)Italia (Italiano)Россия (Русский)대한민국 (한국어)中华人民共和国 (中文)台灣 (中文)日本 (日本語)香港特别行政區 (中文)
 
 
Microsoft Developer Network
 
 
Home
 
 
Library
 
 
Learn
 
 
Downloads
 
 
Support
 
 
Community
 
 
Forums
 
 
 
Microsoft Developer Network > SharePoint Products and Technologies Forums > SharePoint - Development and Programming > Set DateTime in ItemAdding/ItemAdded
Ask a questionAsk a question
Search Forums:
  • Search SharePoint - Development and Programming Forum Search SharePoint - Development and Programming Forum
  • Search All SharePoint Products and Technologies Forums Search All SharePoint Products and Technologies Forums
  • Search All MSDN Forums Search All MSDN Forums
 

AnswerSet DateTime in ItemAdding/ItemAdded

  • Tuesday, September 30, 2008 4:09 PMAggieEngineer2k Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0
    When 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.
    • ReplyReply
    • QuoteQuote
     

Answers

  • Tuesday, September 30, 2008 7:08 PMRafael Mascarenhas Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Vote As Helpful
    0
    You're setting your property as a string it should  be set as Date Time.

    Hope it helps,


    Rafael
    • Proposed As Answer byRafael Mascarenhas Friday, October 03, 2008 2:53 PM
    • Marked As Answer byMichael Washam - MSFTMSFT, ModeratorWednesday, October 22, 2008 3:19 PM
    •  
    • ReplyReply
    • QuoteQuote
     

All Replies

  • Tuesday, September 30, 2008 6:14 PMMichael Washam - MSFTMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0
    It 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.
    • ReplyReply
    • QuoteQuote
     
Need Help with Forums? (FAQ)
 
© 2009 Microsoft Corporation. All rights reserved.
Terms of Use
|
Trademarks
|
Privacy Statement