It was the question in one of the MSDN forum threads.
My second approach was to modify the default value of the field. The first challange here is that one can not find the All Day Event field in the list of fields when using the „Customize Calendar” page, although the field is there when you check the list of fields in the All Events view.
The All Day Event field is a special out-of-the-box field. When you check the Type property of the „All Day Event” field in a calendar list, it returns AllDayEvent. The class that represents this field is the SPFieldAllDayEvent class, that is inherited from the SPFieldBoolean. The field has no default value defied, as the DefaultValue returns null. When you try to modify this property and call the Update() method of the field, you can see that the it has no effect, the DefaultValue of the field remains null.
It is because this field is „inherited” to the list from the Event content type. You can verify this by attaching the content types of the calendar list (there is only one by default, that is Event), and checking the FieldLinks collection of the Event content type. It includes the All Day Event. Here comes the next problem. The SPFieldLink class has no property that can be used to set the default value. Or maybe it has? Yes, it has, just it is not public.
Here comes reflection into the picture. The property is called Default, it is internal and fortunately has both get and set accessors.
Here is the code one can use to set its value, for example from a command line utility:
After running the code, you can try to create a new calendar item, and see that now the All Day Event checkbox is selected, and only the date field for the Start Time and End Time fields are visible.
The advantage of this solution is that you should not modify the NewForm.aspx, it must be run only once and the form is loaded every time with the default value already set. The possible drawback is that tampering with the reflection might be not really supported and can have unforeseeable side-effects to your SharePoint installation, so the code above is really only for demonstration purposes, please use that at your own risk.
Finally I should note, that beyond the specific example I discussed above, the method can be used to set list level default values for the site columns.