SharePoint time Stamp for Folder

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.

January 29th, 2015 9:25pm

Folder don't have those columns, you need to go for document set. They work as like as folder also has metadata.
Free Windows Admin Tool Kit Click here and download it now
January 29th, 2015 11:54pm

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

https://social.technet.microsoft.com/Forums/sharepoint/en-US/c2fbcf54-4abb-4cc8-9153-d4d0bdaa0f82/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.

February 2nd, 2015 3:26am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics