FILE: DSOFILE.EXE Lets You Read Document Properties w/o Office Installed

ID: Q224351


The information in this article applies to:
  • Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, versions 5.0, 6.0
  • Microsoft Excel 97 for Windows
  • Microsoft Word 97 for Windows
  • Microsoft PowerPoint 97 For Windows


SUMMARY

Dsofile.exe is a self-extracting executable that provides an in-process ActiveX DLL for Visual Basic programmers to use in order to read or modify the Document Summary Properties for an OLE Structured Storage file. Because Word, Excel, and PowerPoint use OLE Structured Storage to save their files to disk, this DLL lets programmers view and change document properties without the need to open the document in Office.


MORE INFORMATION

The following file is available for download from the Microsoft Download Center. Click the file name below to download the file:

Dsofile.exe
Release Date: Mar-24-1999

For more information about how to download files from the Microsoft Download Center, please visit the Download Center at the following Web address
http://www.microsoft.com/downloads/search.asp
and then click How to use the Microsoft Download Center.
FileName Size
Dsofile.dll 31.5 KB
FilePropDemo.vbp 835 bytes
FilePropDemo.vbw 52 bytes
FileProp.frm 15.5 KB
FileProp.frx 72 bytes


You have a royalty-free right to use, modify, reproduce and distribute the Dsofile.dll and Visual Basic Sample Application (and/or any modified version) in any way you find useful, provided that you agree that Microsoft has no warranty, obligations or liability for these files.

NOTE: THE DSOFILE.DLL AND ASSOCIATED VISUAL BASIC SAMPLE CODE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.

Document Properties

Every OLE compound document has the ability to store additional information about the document in persistent property sets, collectively called the Document Summary Properties. These property sets are managed by COM/OLE so third-party clients can read this information without the aid of the main application responsible for the file.

To aid developers interested in reading document properties, Microsoft has provided two interfaces to manage property sets: IPropertySetStorage and IPropertyStorage. However, Visual Basic programmers cannot use these interfaces directly because the interfaces are not Automation-compatible. To resolve this problem, Visual Basic developers can now use the included ActiveX DLL to read/write to the most common property sets used in OLE compound documents (particularly those used by Office applications).

NOTE: Dsofile.dll uses IPropertySetStorage and IPropertyStorage internally. These interfaces were defined after the initial release of Windows 95, so Windows 95 users must have one of the following installed on their system for the DLL to work properly:
  • Internet Explorer 4.01 (or later).


  • - or -

  • The DCOM95 Patch. Available for free download at the following Web site:

    http://www.microsoft.com/com/dcom/dcom1_2/dcom1_2.asp

    A trappable error will be raised if the system does not support IPropertySetStorage or IPropertyStorage.


OLE File Property Reader

Dsofile.dll reads and writes to both standard and custom properties from any OLE Structured Storage file. This includes (but is not limited to) Word documents, Excel workbooks, and PowerPoint presentations. Due to its size and speed, the DLL can be much more efficient than trying to Automate Office to read document properties.

To use the Property Reader, you need to register Dsofile.dll on your system (see below). Once registered, the component can be used by both late and early bound clients. To set an early bound reference in Visual Basic, use the References dialog (Project|References) and select the item: "DS: OLE Document Properties 1.0 Object Library." If the item is not listed in the dialog, use the Browse button to find the DLL.

Dsofile.dll has only one creatable object, DSOleFile.PropertyReader. This object provides access to document properties through a single method, GetDocumentProperties. PropertyReader is a top level object and is marked GlobalMultiUse, so you do not need to explicitly create the object to use it. You can call GetDocumentProperties directly if you have already set a reference to the DLL in the References dialog. However, to save resources at run-time, it is recommended that you explicitly create and destroy a PropertyReader object when needed. If you allow Visual Basic to implicitly create the object, it will not be released until your application terminates.

GetDocumentProperties takes the name of an OLE Structured Storage file and returns a DocumentProperties object that you can then Automate to read or modify property values. DocumentProperties provides access to the most common summary information used by Office applications. When the object is created, the specified file is open for exclusive access. If the file is in use by another application when you try to open it, you get a trappable error telling you that the file is locked.

The DocumentProperties object contains a collection of the custom properties associated with the file. Each custom property has a unique name and is accessible in the collection by that name. You can add or remove individual properties and also enumerate through the entire collection using Visual Basic's For Each syntax.

When calling GetDocumentProperties, the PropertyReader will first attempt to open the document for both read and write access. If the file has been marked read-only or is located on an NT share that provides just Read access, the PropertyReader will try to open the document in read access. When open for read-only, you cannot change values for any of the properties. To test whether the document is read-only, use the IsReadOnly method on the DocumentProperties object returned from GetDocumentProperties. The method returns True if the document is read-only.

NOTE: Dsofile.dll was written specifically for use by Visual Basic programmers, but it can be used from any COM-aware language.

In addition to the standard Automation errors, Dsofile.dll can return one of the following custom error messages when something goes wrong:
&H80040201 You need DCOM installed on Windows 95 to run this program.
&H80040202 The file you have selected is not an OLE document.
&H80040203 The file is currently open and cannot be read.
&H80040204 This property can only be called on Word or Excel documents.
Another common error is:
Permission denied (Error 70)
which occurs when attempting to modify a property in a read-only document.

Steps to Setup and Test the DLL

Included is a Visual Basic sample application that demonstrates using the Dsofile.dll to read and write document properties. Before you can run the sample you need to do the following:
  1. Register Dsofile.dll on your system. To do this, copy Dsofile.dll to your system path and then type regsvr32 dsofile.dll in the Run dialog from the Start menu.


  2. Open the project, FilePropDemo.vbp, in either Visual Basic 5.0 or Visual Basic 6.0.


  3. Make sure that Dsofile.dll has been properly referenced by opening the Project|References dialog and selecting the DS: OLE Document Properties 1.0 Object Library.


  4. Press the F5 key to run the project. You will be prompted for a compound document file to open. Select an appropriate file and its document properties are displayed.



REFERENCES

For information on how to read Document Properties from Visual C++, see the following article in the Microsoft Knowledge Base:

Q186898 HOWTO: Read Compound Document Properties Directly with VC++

© Microsoft Corporation 1999, All Rights Reserved.
Contributions by Richard R. Taylor, Microsoft Corporation

Additional query words:

Keywords : kbfile kbole kbActiveX kbAutomation kbExcel kbPersistSt kbPowerPt kbWord kbGrpDSO
Version : WINDOWS:5.0,6.0,97
Platform : WINDOWS
Issue type : kbinfo


Last Reviewed: December 14, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.