SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 1 down vote accepted

You can use below code on page or user control.

public DateTime GetLastModifedForFile()

  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;
share|improve this answer
I'm new to Sharepoint coding... where do I put this on my page? (meaning: how do I incorporate this?) – Mr_Thomas Nov 16 '11 at 16:38
This link can help you to start with : – Amit Kumawat Nov 16 '11 at 16:52
What I ended up doing was inserting a Data View on my page. That allowed me to get what I needed. Thank you, Amit, for sending me down the right road. – Mr_Thomas Nov 16 '11 at 20:11
Dataview will work only if user have permission on library.If not (like you mentioned in your coment in another answer), you have to use SPSecurity.RunWithElevatedPrivileges – Amit Kumawat Nov 17 '11 at 2:38

The Modified column displays this automatically. Be sure to include the column in your view.

share|improve this answer
I see the Modified date when I look at the File Library. I want that date to appear on a page in the site for those that don't have access to look at the 'raw' file library. – Mr_Thomas Nov 16 '11 at 15:56
How are you exposing the library to end users? Are you putting a web part on the publishing page? If so, include the modified date in that view. – Eric Alexander Nov 16 '11 at 16:14
I just have an aspx page with some HTML links to the file where they can download the file. – Mr_Thomas Nov 16 '11 at 16:38
Are you dynamically generating that content? The easiest approach is to add a web part into a web part zone onto your publishing page and expose the desired metadata. Other options include writing some javascript/jQuery to fetch the information using a handy tool called SPServices, – Eric Alexander Nov 16 '11 at 16:43
The Excel file is uploaded once every two weeks. It's always called the same thing ("Deposit.xls"). When the user hits the site page, there's a link there that allows them to download the file. I'll look at that SPServices tool. I've seen that listed before as helping in certain situations. – Mr_Thomas Nov 16 '11 at 16:49

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.