priya thapliyal
priya thapliyal

Reputation: 81

Get last save date of excel document in C#

Today,I got badly stuck in getting excel last save date.Its not modified date.Any help would be highly appreciated.I was trying following code for last save date instead of created date but I couldn't make it work.Could anybody confirm that below method worked for them?

DSOFile.OleDocumentPropertiesClass oleDocumentPropertiesClass = new DSOFile.OleDocumentPropertiesClass();
oleDocumentPropertiesClass.Open("C:\\My Documents\\MyExcelFile.xls");
MessageBox.Show(oleDocumentPropertiesClass.SummaryProperties.DateCreated.ToString());

Upvotes: 1

Views: 2069

Answers (2)

Reinstate Monica Please
Reinstate Monica Please

Reputation: 11593

Using the excel interop assembly

var workbook = new Application().Workbooks.Open(@"somePath.xls", ReadOnly: true);
var lastSavedDate = (DateTime)workbook.BuiltinDocumentProperties["Last Save Time"].Value;

Full list of properties

Title
Subject
Author
Keywords
Comments
Template
Last Author
Revision Number
Application Name
Last Print Date
Creation Date
Last Save Time
Total Editing Time
Number of Pages
Number of Words
Number of Characters
Security
Category
Format
Manager
Company
Number of Bytes
Number of Lines
Number of Paragraphs
Number of Slides
Number of Notes
Number of Hidden Slides
Number of Multimedia Clips
Hyperlink Base
Number of Characters (with spaces)

Upvotes: 3

Peter M.
Peter M.

Reputation: 1269

You could do it without using the Office library, by checking the last-modified date of the file in the file system:

using System.IO;
var time = new FileInfo(@"C:\My Documents\MyExcelFile.xls").LastWriteTime;

Upvotes: 4

Related Questions