[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2269
  • Last Modified:

How to access document properties via Dsofile from VBscript

Im need to access builtindocumentproperties for various documents; word, excel etc, and I need to use VBScript (not VBA or VB).

Does anyone know how to do this?


0
John_E_Lewis
Asked:
John_E_Lewis
  • 2
1 Solution
 
JohnModigCommented:
First, you should download and run the DSOFILE component. If you haven't already, that could be done here:
http://www.microsoft.com/downloads/details.aspx?familyid=9ba6fac6-520b-4a0a-878a-53ec8300c4c2&displaylang=en
This is a self-extracting ZIP file that contains a copy of DSOFILE.DLL as well as some sample code. Second, place a copy of the DLL in your Windows/System32 subdirectory, then run "regsvr32 dsofile.dll" to register it.
Next, create a virtual Web root and open a new ASP document in it. The code should be something like this:

<%@ Language=VBScript %>
<% option explicit %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>
<table width="100%" border=1>
<TR><TH width="25%">Title</TH><TH width="10%">Size</TH>
<TH width="10%">Date</TH><TH width="*">Description</TH></TR>
<%
    dim objPropReader         ' Property Reading object
    dim objFileProps          ' Object that stores the file
                              ' properties
    dim objFSO                ' File System Object
    dim objFile               ' File Object
    dim objFolder             ' Folder Object
    dim sMapPath              ' String to store the Real Path

    on error resume next    
    '
    ' Create File System Object to get list of files
    '
    set objFSO = createobject("Scripting.FileSystemObject")
   
    '
    ' Set the Property Reader to get the file properties
    '
    Set objPropReader = CreateObject("DSOLEFILE.PropertyReader")    
   
    '
    ' Get the Windows NT path for the web page
    '
    sMapPath = Server.MapPath(".")
   
    '
    ' Set the folder object to the Mapped Path
    '
   
    set objFolder = objFSO.GetFolder(sMapPath)
   
    '
    ' For each file in the folder
    '
    for each objFile in objFolder.files        
       
        '
        ' Read the file properties so we have the Title and
        ' Description. In order to do this we need to use the
        ' .PATH which contains the path and the file name.
        ' .NAME only contains the file name.
        '
        set objFileProps=
            objPropReader.GetDocumentProperties(objfile.path)
        if err.number = 0 then
            %>
             <TR><TD width="25%">
             
             <A HREF="<%=objFile.Name%>"><%
             '
             ' Having used the name of the file in the HREF
             ' above, now we need to check to see if we have a
             ' title to use. If we don't have a title
             ' then we'll use the file name.
             '
             if trim(objFileProps.Title) = "" then
                Response.Write objFile.Name
             else
                Response.Write trim(objFileProps.Title)
             end if%></a></TD>
             
             <TD width="10%" align="Right">
             <%
             
             '
             ' We'll format the file size so it looks pretty.
             '
            if objFile.size < 1024 then
                Response.Write objFile.size & " Bytes"
            elseif objFile.size < 1048576 then
                Response.Write round(objFile.size/1024,1) & "KB"
            else
                Response.Write round((objFile.size/1024)/1024,1)
                    & "MB"
            end if
             %></td>
             <TD><%=objFile.DateLastModified %></TD>
             <TD width="*">  <%=objFileProps.Comments%> </TD>
             </tr>
            <%
        end if
        err.clear
    next
%>
</table><BR><BR>
</BODY>
</HTML>

Read more here:
http://msdn.microsoft.com/msdnmag/issues/0300/fso/default.aspx
0
 
steven98Commented:
<%
Dim fs,f
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.GetFile("c:\test.txt")
Response.Write("File created: " & f.DateCreated)
set f=nothing
set fs=nothing
%>

Output: File created: 9/19/2001 10:01:19 AM

example from
http://www.w3schools.com/asp/asp_ref_file.asp

works on all kinds of file type

0
 
JohnModigCommented:
Well, the question was about how to do 'properties via DSOFILE', not just FileSystemObject right?
0
 
John_E_LewisAuthor Commented:
Thanks,

   An excellent response.

   Also, worth looking at:

http://download.microsoft.com/download/office97dev/utility/2/win98/en-us/dsofile.exe

Also, not sure if its relevant but other examples use ""DSOleFile.PropertyReader" rather than "DSOLEFILE.PropertyReader"
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now