Sunday, September 28, 2008

Updating List Item for recalculate the Calculated Columns

Scenario:
You are using calculated columns in your list and you have reference to Today.

Solution:
Run a nightly job

Code:

using Microsoft.SharePoint;
using System.Configuration;

namespace UpdateSPList
{
class Program
{
static void Main(string[] args)
{
using(SPSite site = new SPSite(ConfigurationManager.AppSettings["Site"])) {
using(SPWeb web = site.OpenWeb()) {

SPList list = web.Lists[ConfigurationManager.AppSettings["List"]];
web.AllowUnsafeUpdates = true;
foreach (SPListItem item in list.Items)
{
item.SystemUpdate();
}
web.AllowUnsafeUpdates = false;
}
}
}
}
}
Application Configuration File:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="Site" value="http://My_Portal/Sites/TheSite"/>
<add key="List" value="Tasks"/>
</appSettings>
</configuration>
Article:

0 comments: