How To Set date Expiration to Today in Announcement list
Suppose we want to set the Expiration date to Today + 30 days after an item has been created for a list suppose Announcements list, this we can achive by using SharePoint object model.
using (SPSite site = new SPSite("http://SiteURL"))
{
using (SPWeb web = site.RootWeb)
{
SPList list = web.Lists.TryGetList("Announcements");
if (list != null)
{
SPField field = list.Fields[SPBuiltInFieldId.Expires];
field.DefaultFormula = "=TODAY()+30";
field.Update();
}
}
}
No comments:
Post a Comment