I want to retrieve a date field value from a List and store it into a string variable as part of the an ItemAdded EventReceiver.
In the example below both ItemManager and stringSubject get set correctly but when the stringStartDate is being assigned the following error is generated:
“NullReferenceException was unhandled by user code : Object reference not set to an instance of an object.”
I just need to know how to assign the List date field to a string variable?
Thanks
foreach (SPListItem item in myCustomList.Items)
{
string ItemManager = item["Manager"].ToString();
string stringSubject = item["Subject"].ToString();
string stringStartDate = item["StartDate"].ToString;
}
If
item["StartDate"]is aDateTime?you can do something like this:You also missed
()off the end ofToString().Obviously, you may want to replace
string.Emptywith some other value such asDateTime.Now.ToString().