below is the code to update folder "ModifiedDate" when a new item is added or updated to the document library. it updates all, in case if you have more than one level of folder structure. here problem is it executes every time when you add/update any items to this Library. for example if you have 3 levels of folder structure this event calls 3 times as well.
i dont think it is a good practice...still if you have this kind of requirement from your client you can use below code.
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('/'));
// string folderName = folderPath.Substring(folderPath.LastIndexOf('/') + 1);
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();
}
}
}
}
}
}
}