How to access document properties via Dsofile from VBscript

Posted on 2005-04-12
Last Modified: 2012-06-27
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?

Question by:John_E_Lewis
    LVL 11

    Accepted Solution

    First, you should download and run the DSOFILE component. If you haven't already, that could be done here:
    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 %>
    <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
    <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=
            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
                    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"
                    Response.Write round((objFile.size/1024)/1024,1)
                        & "MB"
                end if
                 <TD><%=objFile.DateLastModified %></TD>
                 <TD width="*">  <%=objFileProps.Comments%> </TD>
            end if

    Read more here:

    Expert Comment

    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

    works on all kinds of file type

    LVL 11

    Expert Comment

    Well, the question was about how to do 'properties via DSOFILE', not just FileSystemObject right?

    Author Comment


       An excellent response.

       Also, worth looking at:

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

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
    Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL ( several years ago, it seemed like now was a good time to updat…
    Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now