I want to set the default value for the sharepoint's built-in field ArticleStartDate programmatically. But I am unable to do so. My code is as follows:

SPField articleDate = currentWeb.Fields[FieldNames.ArticleStartDate];
if (articleDate != null)
    articleDate.DefaultValue = Microsoft.SharePoint.Utilities.SPUtility.CreateISO8601DateTimeFromSystemDateTime(DateTime.Today);

I debugged the program and found the error at the statement SPField articleDate = currentWeb.Fields[FieldNames.ArticleStartDate]; after executing this statement control directly goes to the Catch() statemenets and displays the error message only false. What should I do?

1 Answer 1


Try with the following code,

SPFieldDateTime articleDate =(SPFieldDateTime ) currentWeb.Fields[FieldNames.ArticleStartDate];


SPFieldDateTime - Represents a field that contains date and time values.

  • It is working perfectly, as per your answer Sir, but thing I want to achieve is to make the today's date selected. The image is here, and what I am getting is here
    – users1100
    Dec 24, 2013 at 6:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.