I have an Excel file that is in a file library. I'd like to have a page that shows when that Excel file was last modified.
Anybody know of a piece of code that will show "Date Modified" of an Excel file in a file library?
You can use below code on page or user control.
public DateTime GetLastModifedForFile()
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite siteColl = new SPSite("http://spsite"))
{
using (SPWeb web = siteColl.OpenWeb())
{
SPFile spfile = web.GetFile("Source_Folder_Name/Source_File");
if (spfile.Exists)
{
return spfile.TimeLastModified;
}
}
}
});
return null;
}
The Modified column displays this automatically. Be sure to include the column in your view.
I achieved this by using document webpart, and modifying the current view to show only name and modified and filtered it with the file name, disable tool bar etc as per your need. Amit's solution is the best one, but I had to use this because inside our company environment we are not allowed to add any scripts or can we use share-point designer.