开发者

Adding an existing site column to a custom list

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 colum开发者_运维问答n (which is a built in field) to this Custom List. How do I do this programmatically?


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();
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜