Click here to Skip to main content
15,881,882 members
Articles / Programming Languages / C#
Article

View/Modify Office File Properties using OLE

Rate me:
Please Sign up or sign in to vote.
3.00/5 (7 votes)
22 Jun 2005 77.5K   1.3K   19   11
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:

C#
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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionUsing the DLL on opened file Pin
Carsten Giesen12-Dec-14 2:41
Carsten Giesen12-Dec-14 2:41 
GeneralUsing IPropertyStorage Pin
Sweetdin16-Feb-10 2:44
Sweetdin16-Feb-10 2:44 
GeneralUnauthorizedAccessException Pin
chawkinsuf25-May-07 6:24
chawkinsuf25-May-07 6:24 
I am trying to edit the summary properties of mpeg files using DSOFile. I am using Interop.Dsofile.dll and everything works except when I try to set the properties of a file that has never had them set before. When I attempt that I get the following exception from the DSOFile.SummaryProperties.set_Author(String pbstrAuthor) function (or whatever property I try to set):

System.UnauthorizedAccessException
{"Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"}

If I right click on the file and add any property, I can alter them all without a problem. So I gues my question is how do I get the summary properties into a file that has never had them before?

Thanks,
Chris
GeneralRe: UnauthorizedAccessException Pin
Vivek Singh - IN25-May-07 15:29
Vivek Singh - IN25-May-07 15:29 
QuestionWhat about non-office files? Pin
B.V.Papadopoulos15-Feb-07 8:38
professionalB.V.Papadopoulos15-Feb-07 8:38 
AnswerRe: What about non-office files? Pin
Vivek Singh - IN18-Feb-07 18:10
Vivek Singh - IN18-Feb-07 18:10 
GeneralRe: What about non-office files? Pin
B.V.Papadopoulos22-Feb-07 23:07
professionalB.V.Papadopoulos22-Feb-07 23:07 
GeneralRe: What about non-office files? Pin
S. Calistio28-Jul-07 5:48
S. Calistio28-Jul-07 5:48 
Generalsmall help Pin
samasavinirs6-Mar-06 22:43
samasavinirs6-Mar-06 22:43 
GeneralBeware using wrong version of DSOFile.DLL Pin
gxdata22-Jun-05 22:06
gxdata22-Jun-05 22:06 
GeneralRe: Beware using wrong version of DSOFile.DLL Pin
Vivek Singh - IN22-Jun-05 22:18
Vivek Singh - IN22-Jun-05 22:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.