views:

57

answers:

2

I think I'm going mad - this seemed like an easy thing to do but I can't find any info on it at all.

I have created a Custom List and added 4 columns to it. Created By and Modified By are already in the list but hidden from the view.

I want to add a Date Modified column (which is a built in field) to this Custom List. How do I do this programmatically?

+2  A: 

Are you trying to add the column to the list or to a view? The Date Modified column should be added to the list by default. To add it to the view (i.e. so it shows up when you navigate to the list) you can use code similar to the following:

using (SPWeb web = new SPSite("http://intranet/").OpenWeb())
{
    SPList customList = web.Lists["CustomList"];
    SPView defaultView = customList.DefaultView;

    defaultView.ViewFields.Add("Modified");
    defaultView.Update();
}
Ari
A: 

With sharepoint sometimes you must do ugly things... stuff you would not want your children know when they grow up.

Here is a pitifull solution: - you create a DateTime field just like any other. - you create a workflow when data changes, workflow starts, updates that your custom modified field and then stops.

ANYWAY, I know it is possible to show the default Modified field, perhaps you wanna go in that direction a little bit more.

Daniel Dolz
que mala vibra chabón, me votan en contra sin avisar porque
Daniel Dolz