Hi,
Can anyone help me with an event handler for updating the Modified time stamp of a Folder in a Document library? As you know we can get this updated for a file but not for a folder. Please help.
Technology Tips and News
Hi,
Can anyone help me with an event handler for updating the Modified time stamp of a Folder in a Document library? As you know we can get this updated for a file but not for a folder. Please help.
Hi,
If you want to update the Modified time stamp of a Folder in a Document library, the following code snippet for your reference:
public override void ItemUpdated(SPItemEventProperties properties) { base.ItemUpdated(properties); if (properties.List.BaseTemplate.ToString() == "10017") // working documents { using (SPSite site = new SPSite(properties.SiteId)) { using (SPWeb web = site.OpenWeb()) { if (properties.ListItem.Url != null) { string listItemUrl = properties.ListItem.Url; string folderPath = listItemUrl.Remove(listItemUrl.LastIndexOf('/')); SPFolder folder = web.GetFolder(folderPath); if (folder != null) { SPListItem spitem = folder.Item; if (spitem != null && spitem[SPBuiltInFieldId.Modified] != null) { spitem[SPBuiltInFieldId.Modified] = DateTime.Now; spitem.Update(); } } } } } } } public override void ItemAdded(SPItemEventProperties properties) { base.ItemAdded(properties); if (properties.List.BaseTemplate.ToString() == "10017") // working documents { using (SPSite site = new SPSite(properties.SiteId)) { using (SPWeb web = site.OpenWeb()) { if (properties.ListItem.Url != null) { string listItemUrl = properties.ListItem.Url; string folderPath = listItemUrl.Remove(listItemUrl.LastIndexOf('/')); SPFolder folder = web.GetFolder(folderPath); if (folder != null) { SPListItem spitem = folder.Item; if (spitem != null && spitem[SPBuiltInFieldId.Modified] != null) { spitem[SPBuiltInFieldId.Modified] = DateTime.Now; spitem.Update(); } } } } } } }
More information:
Sharepoint 2010: Folder Modified Date doesn't get updated
http://suryapulipati.blogspot.com/2011/08/sharepoint-2010-folder-modified-date.html
SharePoint 2013 Folder modified date does not change
Thanks,
Dennis Guo
TechNet Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
tnmff@microsoft.com.