WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

DSOFILE
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Get & Set Office Document Properties


Keywords: MSOFFICE office document properties summary

The DSOFILE component lets you retrieve and edit office document properties from Winbatch.

Dsofile.exe is a self-extracting executable that provides a simple in-process ActiveX component for programmers to use in order to read and modify the Document Summary Properties for an OLE Structured Storage file such as native Excel, PowerPoint, Microsoft Visio, and Word documents. The component can also work on non-OLE documents when it is run on Windows 2000 with an NTFS file system.

Note: you will need to install the DSOFILE.DLL file and register it, in order to run the following example.

http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/Q224/3/51.asp

First, download and run the DSOFILE component. This is a self-extracting ZIP file that contains a copy of DSOFILE.DLL. Second, place a copy of the DLL in your Windows System32 subdirectory, then execute:

To register the component use:

; The OLE Document Property Reader COM module.
DirChange(DirWindows(1))
sOLEDLL = "DSOFILE.DLL" 

; Register the COM component.
iResult = DllCall(sOLEDLL,long:"DllRegisterServer")
If iResult Then Exit ; Terminate immediately.

To unregister the component use:

; The OLE Document Property Reader COM module.
DirChange(DirWindows(1))
sOLEDLL = "DSOFILE.DLL" 

; Unregister the COM component.
iResult = DllCall(sOLEDLL,long:"DllUnregisterServer")

Now that you have the Document Summary Properties component installed you can now begin accessing the document summary properties.


Here is an example that works with Word:

;////////////////////////////////////////////////////////////////////////
; WinBatch - display select property information for Word Document
; Deana Falk. - 06/07/2006
; This code requires WinBatch 2004B or newer
;////////////////////////////////////////////////////////////////////////

file = "C:\Temp\WordTemp.doc"
If !FileExist(file) Then Exit

oDocProps = ObjectCreate("DSOFile.OleDocumentProperties")

; When the Open method is called, the OleDocumentProperties object that is named Dsofile tries to open the document for both 
; read access and write access. If the file has been marked read-only or if the files is located on an NTFS share that only 
; provides Read access, the call may fail. You may receive the following error message: Error 70: Permission denied
; If you want to open the file for read access only , pass True for the ReadOnly parameter on the Open method. Additionally, 
; you can pass the dsoOptionOpenReadOnlyIfNoWriteAccess (shortend to dsoReadOnlyNoWriteAccess) flag if you want Dsofile to try to open the file for editing. However, 
; if Dsofile cannot gain access because file is read-only or is locked by another process, open a read-only copy. Then, you can 
; verify whether the document is opened read-only by using the IsReadOnly property.
ReadOnly = @true
dsoReadOnlyNoWriteAccess = 2
oDocProps.Open(file,ReadOnly,dsoReadOnlyNoWriteAccess)

oSummaryProps = oDocProps.SummaryProperties

txt = ""
txt = StrCat(txt,"Caption: ",oSummaryProps.ApplicationName,@CRLF)
txt = StrCat(txt,"Title: ",oSummaryProps.Title,@CRLF)
txt = StrCat(txt,"Author: ",oSummaryProps.Author,@CRLF)
txt = StrCat(txt,"Word Count: ",oSummaryProps.WordCount,@CRLF)
txt = StrCat(txt,"Page Count: ",oSummaryProps.PageCount,@CRLF)   
txt = StrCat(txt,"Version: ",oSummaryProps.Version,@CRLF)
txt = StrCat(txt,"Revision Number: ",oSummaryProps.RevisionNumber,@CRLF)
txt = StrCat(txt,"Date Last Saved: ",oSummaryProps.DateLastSaved,@CRLF)
Message("Properties for %file%",txt)

oSummaryProps = 0
oDocProps = 0
exit

Note: Sadly, DOSFile supports only "Structured OLE documents." In plain English, this means that it is worthless against the new "x" documents (DOCX for Word 2007/2010, XLSX for Excel 2007/2010, PPTX for PowerPoint 2007/2010) etc.

Reference:

http://msdn.microsoft.com/library/en-us/dnoffdev/html/vsofficedev.asp?frame=true#vsofficedev_topic20


Article ID:   W16068
File Created: 2010:12:01:10:26:04
Last Updated: 2010:12:01:10:26:04