65.9K
CodeProject is changing. Read more.
Home

View/Modify Office File Properties using OLE

starIconstarIconstarIconemptyStarIconemptyStarIcon

3.00/5 (7 votes)

Jun 23, 2005

viewsIcon

78478

downloadIcon

1258

This article allows to view/modify the file summary properties.

Sample Image - DSOFileDemo.gif

Introduction

In one of my projects, I wanted to send additional information with file like version history, created by, approved by, etc. when my files are viewed by my users in offline mode (they have downloaded the files from Intranet and read it) without using any external data repository like XML/TXT. So I thought utilizing the summary tab of files and it will not require any external data repository.

As per my application requirement, I just had to work with .DOC, .XLS and .PPT files, so I used the DSO to perform this task.

Using the code

This is a simple code snippet which fetch the file information, and update it once you have modified the information. Here is code which does the core work:

private DSOFile.OleDocumentPropertiesClass myDSOOleDocument = 
    new DSOFile.OleDocumentPropertiesClass();
/***************************************************** 
* Opening file 
* ***************************************************/ 
openFileDialog1.ShowDialog(); 
myDSOOleDocument.Open(openFileDialog1.FileName,false , 
     DSOFile.dsoFileOpenOptions.dsoOptionOpenReadOnlyIfNoWriteAccess); 


/***************************************************** 
* Reading from file through DSO and writing values to form 
* ***************************************************/ 
txtTitle.Text = myDSOOleDocument.SummaryProperties.Title; 
txtSubject.Text = myDSOOleDocument.SummaryProperties.Subject; 
txtAuthor.Text = myDSOOleDocument.SummaryProperties.Author; 
txtCategory.Text = myDSOOleDocument.SummaryProperties.Category; 
txtKeyword.Text = myDSOOleDocument.SummaryProperties.Keywords; 
txtComment.Text = myDSOOleDocument.SummaryProperties.Comments ;


/***************************************************** 
* Reading from form and writing values to File summary through DSO 
* ***************************************************/ 
myDSOOleDocument.SummaryProperties.Title = txtTitle.Text; 
myDSOOleDocument.SummaryProperties.Subject = txtSubject.Text; 
myDSOOleDocument.SummaryProperties.Author = txtAuthor.Text; 
myDSOOleDocument.SummaryProperties.Category = txtCategory.Text; 
myDSOOleDocument.SummaryProperties.Keywords = txtKeyword.Text; 
myDSOOleDocument.SummaryProperties.Comments = txtComment.Text; 
myDSOOleDocument.Save();

Points of Interest

I was able to provide user friendly search without even opening file, just with the help of DSO. This can be a straight forward approach to create small knowledge base too.

History

Initial version added on 23 June, '05.