Extracting Microsoft Office Application Properties without automation

Every file created by a Microsoft Office application supports a set of built-in document properties. In addition, you can add your own custom properties to an Office document either manually or through code. You can use document properties to create, maintain, and track information about an Office document such as when it was created, who the author is, where it is stored, and so on. To get or set the properties you can use automation to extract the Microsoft Office application properties.

Take a look at the following links for samples:



But what happens if you are working with a Web-based application and you want to avoid the use of automation in a Web server…

I found a nice workaround to extract Office document properties without using automation. You can use the Dsofile, an in-process ActiveX component that allows you to read and to edit the OLE document properties that are associated with Microsoft Office files, such as the following:
• Microsoft Excel workbooks
• Microsoft PowerPoint presentations
• Microsoft Word documents
• Microsoft Project projects
• Microsoft Visio drawings
• Other files without those Office products installed

If you are working with a managed application follow the next steps:

  1. Download and install the DSO File control.
  2. Add a reference to InteropDSOfile.dll to your managed Web application.
  3. Create a new Web form and copy the following code.

    <%@ Page Language=”C#” %>

    <script runat=”server”>
    protected void btnLoadFile_Click(object sender, EventArgs e)
    // Define a path to save the file in the server
    string serverTempFilePath Server.MapPath(@”/yourpath/” + FileUpload1.FileName);

    // Create the DSOFile document
    DSOFile.OleDocumentPropertiesClass oleDocument = new DSOFile.OleDocumentPropertiesClass();
    DSOFile.SummaryProperties summaryProperties;


    // Extract the properties
    summaryProperties oleDocument.SummaryProperties;
    tbTitle.Text summaryProperties.Title;
    tbAuthors.Text summaryProperties.Author;
    tbCompany.Text summaryProperties.Company;
    tbNumPages.Text summaryProperties.PageCount.ToString();
    tbWordCount.Text summaryProperties.WordCount.ToString();

    // Close the DSOFile.OleDocumentPropertiesClass

    <html xmlns=”http://www.w3.org/1999/xhtml”>
    <head runat=”server”>
    <form id=”form1″ runat=”server”>
    </strong><br />
    br />
    table border=”1″>
    <td valign=”top”>
                            File upload:
    <asp:FileUpload ID=”FileUpload1″ runat=”server” />
    asp:Button ID=”btnLoadFile” runat=”server” OnClick=”btnLoadFile_Click” Text=”Load File Properties” /><br />
    <asp:TextBox ID=”tbTitle” runat=”server”></asp:TextBox> 
    <asp:TextBox ID=”tbAuthors” runat=”server”></asp:TextBox> 
    <asp:TextBox ID=”tbCompany” runat=”server”></asp:TextBox> 
                            Number of Pages:
    <asp:TextBox ID=”tbNumPages” runat=”server”></asp:TextBox></td>
                            Word count:
    <asp:TextBox ID=”tbWordCount” runat=”server”></asp:TextBox> 

  4. If you run the previous Web form you will get something like this:

You can also extract custom properties using the DSOFile control.

Have a peek and enjoy!

Comments (56)

  1. Bill says:


    Just wondering if you had any luck with setting or extracting OLE properties for PDF or even Outlook Message files ?



  2. Hi Bill,

    I only tried using DSOControl for Office files. However, you can always try extracting generic file properties using the System.IO.FileInfo class:


  3. EdgE says:

    It’s is possible to change (custom)properties of other files (like pdf, txt, bmp) BUT when these files are compressed or burned on cd, these properties are lost.

    This is not the case for MS-Office files.


  4. Namrata says:


    how do i extract document properties for pdf files in C#? FileInfo class doesnot give details like author, keywords, comments and other properties in which i am interested.



  5. fred says:

    Looks like the microsoft DSOfile DLL V2.0 (09 feb 06)is bugged : i can update file summary fields only if they’ve been set manually before (in particular for the "title" field). Otherwise, i get a stupid "persmission is denied" error message, though i’m running locally with admin rights.

    The DLL VB6 and .NET demos crash the same if these fields were not manually set before !

    This is pretty annoying. I’ve been looking for an explanation on the web for hours but couln’t find any. Microsoft should care more about the quality of its code.

  6. Emeric says:

    I have exactly the same problem as Fred: can’t update the "title" and "category" fields if they were not manually set before.

    I’m looking for a not bugged component who can update summary fields for PDF files.

  7. Erika Ehrli says:

    Just a little comment to clarify the scope of the DSOfile dll. The Microsoft Developer Support OLE File Property Reader 2.0 is a code sample that demonstrates how to use the OLE IPropertyStrorage interface to read and write the document properties of OLE files, such as the properties of native Microsoft Word, Microsoft Excel, Microsoft PowerPoint, Microsoft Publisher, and Microsoft Visio files.

    The sample was not intended to work with PDF files…

  8. Erika Ehrli says:

    Emeric and Fred, it seems that you have an authorization problem here. That is because, the sample code opens the files as read only and with no write Access:

    m_oDocument.Open(sFile, fOpenReadOnly, DSOFile.dsoFileOpenOptions.dsoOptionOpenReadOnlyIfNoWriteAccess)

    See the sample code and check out the following comment and line of code:

    ‘ Here we can tell if file was open read-only…

    m_fOpenedReadOnly = m_oDocument.IsReadOnly

    I also found this comment as part of the sample code:

    ‘The dsoOptionOpenReadOnlyIfNoWriteAccess allows us to open the file, read/write if we have access, but go ahead and open read-only if

    we don’t. Since viewing properties is main purpose of the sample it is OK for us to fail write access lock on this open…

    I hope this helps,


  9. Emeric says:

    Thanks for your help Erika, but had the same problems with Word files: could’nt update the "title" and "category" fields if they were not manually set before.

    But I find the solution and here it is:


    All you have to do is to debug the dsofile by yourself. Just follow the instruction given in the link, it’s not very difficult and it works fine, even for pdf files.

  10. Erika Ehrli says:

    Emeric and everyone,

    I am sorry that the DSOFile control has problems to set fields (title and summary) that were not manually set before.

    I loved this control because it was great for extracting properties and my intentions to share this with the community were the best. I am sure some people might find this useful however.

    I also want to share that Ken Getz just wrote a new column on how to extract document properties using Office 2007.


    You will see it’s quite interesting and I love the fact that the new file formats offer better ways to extract/update document properties and override the need to use automation or the DSOControl.

    Extracting/writing document properties contained in an XML document is very simple, I am sure everyone will be delighted with this new option.

  11. Sunith Nair says:

    If you want to access the files that are on a remote machine and you are trying to use impersonation then you will need to use AspCompat="true" for the page trying to access the file. Take a look at this KB for more information http://support.microsoft.com/kb/325791

    -Sunith Nair

  12. Isaih says:

    Hi I’ve used dsofile.dll tp develop an application. Dsofile.dll fails to register when I deploy to another computer even though it returns a "registration successful" method when regsvr32 is used at the command line.

    Any ideas?


  13. Antony says:

    What is the best way t0 get PDF properties ? Can this be used ?

  14. Henrik says:


    I have also tried this component and used both versions that I know of. However, when I upgraded to version 2, I can no longer store properties with empty strings ("") as values. If so, Windows will no longer display any custom properties on the properties tab (even though they are there). And if opening the file in Word, and then trying to look at the custom properties, Word will crash. How come this is? Is there anyone that has a workaround?

  15. John Rummell says:

    Thanks for the example, this is great.  I can’t getting working though …

    I’m getting an Access denied error on the line that instantiates the DSOFile.OleDocumentPropertiesClass object … any ideas?

  16. John Rummell says:

    I got it working – had to fix security for com applications.

  17. John Rummell says:

    Since I’ve received a few emails on how I fixed my issue, I’ll drop the link to my solution here –> http://forums.asp.net/thread/1409599.aspx

  18. James says:

    Please forgive as this may be a very simple fix. I am very new to programming but have beeb spending many late nights on this.  I keep getting the following error:

    Compiler Error Message: CS0246: The type or namespace name ‘DSOFile’ could not be found (are you missing a using directive or an assembly reference?)

    I do have the reference and the dll is registered both on my local machine and server.  I even tried to Import Namespace="DSOFile" and "Interop.DSOFile" and "InteropDSOFile" and none of that worked.

    Please help.



  19. Nike says:

    Maybe a simple thought but, if there’s a fix for this issue, why doesn’t ms release a new version of the DSOFile.dll with the fix embedded? Seems logical to me…

  20. roylasris says:

    So how can I extract, let’s say, a document’s subject in a docx (2007) Word file. DSOfile doesn’t seem to work against a docx file.



  21. roylasris says:

    Part 2: I have studied Erika’s letter and Ken Getz’ article, but am still confounded as to how I can, within a VBA project, extract, let’s say, the ‘subject’ of an unopened Word2007 document. (I can do it with an open document without any problem. Its the unopened ones that give me a problem.)

    Given how simple 2007 is supposed to make investigating the various parts of a docx document, it would seem that it should be an easier process.  (Ken’s article (for a VBA person such as myself) is way beyond me.) Is there a simple ‘replacement’ for dsofile in 2007?


  22. Rifmetroid says:

    Sorry my English isn’t very well, but i’ll try.

    Does anybody use the dsofile.dll under Windows XP64?

    Does it work? I have some Problems with it and i want to fix it.


  23. Liesha says:

    Has anyone tried using DSO for files on a mapped drive or a  remote network location ..

    Would be obliged if one could suggest how it works…



  24. A. Mandl says:

    Hello, I am trying to get the digital Signiture with DSO File. It is enough for me to find out weather an office file is signed or not (I don’t need to proof the signiture or get the signiture…)

    is this possible?



  25. A. Mandl says:

    Hello, another question:

    with DSOFile 1.4 it was possible to find out if a macro was attached to an Office File – with DSOFile 2.0 I have not found this opportuity?!

    Am I doing something wrong?

    regards Alex

  26. Pachara says:

    Hi Erika

      I have some question. I need add Summary Properties for file(xls,pdf,txt,…..) by C#. But When I complie this program completed and right click this file. file summary properties it is enable. it can’t change summary properties by manual.

     when open file with DSOFile it Error:"A lock violation has occurred. (Exception from HRESULT: 0x80030021 (STG_E_LOCKVIOLATION))"

    Thank you


  27. A.Mandl says:

    Hi again: has anyone a full list of the Documentproperties and their types? than I can extend the DSOFile source…

    cheers alex

  28. Pachara says:


    I make program use C# for edit summury properties file. it can’t open file .txt.

    –**code exsample**—

    String filePath = "C:myfile.txt";

    myDSOOleDocument.Open(filePath, false, DSOFile.dsoFileOpenOptions.dsoOptionOpenReadOnlyIfNoWriteAccess)

    myDSOOleDocument.SummaryProperties.Keywords = txtKeywords.text;


  29. sth_Weird says:


    I’m afraid the sample doesn’t work for me, either.

    It doesn’t throw any exception when I simply open a file, but it can’t write anything. Neither with the sample application nor with my own c# crogramme. I get an access denied error every time I try and the programme crashes.

    The file I tried to use is a simple txt file I created using C#.

    When using the OleDocumentPropertiesClass to open a file in my c# code I get an exception that the file has no ole storage.


  30. Pachara says:


    You can’t show your sample code for me.

    thank you very much.

  31. TrevG says:


    I don’t have a C complier to rebuild the DSOFILE.dll as described by Emeric in May.

    Can anyone e-mail me the patched DSFILE.DLL to tjg001@tpg.com.au

    Regards ….. Trevor G

  32. Amit says:


    dso Document Properties does not match with document properties shows in File->property window in application.

    PLease check it.

    i think this bug in dso dll.



  33. tmlay says:

    Column handlers in XP do not look at the same property set fields as in Windows 2K.

    I have an application that allows you update propery fields like author and comments for a variety of file types including PDF’s. The information is properly displayed for all file types in windows 2K.

    In windows XP, the author and comments fields are not displayed for multi-media files (jpg, gif etc.) in Windows Explorer although if you reinvoke my shell extension the values are there.

    Is there any documentation on other property sets? and which property sets are referenced by different column hanlders in Explorer??



  34. Sandeep Mishra says:


    I have a problem with DSOFile 2.0,I am trying to identify that whether a macro is attached to my document using DSOFile.

    How this can be obtained.



  35. Sandeep Mishra says:

    Hi Erika,

    I have a problem with DSOFile 2.0,I am trying to identify that whether a macro is attached to my document using DSOFile.

    How this problem can be solved.Coz there is no direct property in DSOFile 2.0 to identify a macro in my document.

    looking for your reply,its urgent.

    Do any one else know the solution to this?



  36. Dave Kolb says:

    I installed the latest version of dsofile and find that using the FilePropDemoVB7 program and merely looking at a file adds ADS files to the file being looked at even while it shows you there are no extended properties. At least it did for me for .txt, .rtf and .htm files. Has anyone else experienced this? Hopefully dsofile will be fixed to not do this. This is a bug in either the demo program of dsofile is it not? Thanks, Dave

  37. Dave Kolb says:

    Also, is there anyway to get Vista explorer to show the new properties? I added a "description" to a .txt file and turned on "description" in the explorer view for that folder but did not see the description data I entered. Dave

  38. Lakshminarayana says:


    I have used DSOFile.dll v2.1 to read and write the custom properties of the document. When opened the custom properties tab by right-clicking on the file, no properties are visible even though they are present with the file.

    These properties are visible if I open up the document and view the properties from the File menu.

    Why cannot I see them by right clicking on the file itself? That too, this is happening with only few documents.

    If I re-open the file using the following code snippet and closes it, it shows up the same custom properties by right-clicking them. But this solution doesn’t help me in my project.


           If strWindowsFilePath.Substring(strWindowsFilePath.IndexOf(".") + 1, 3) = "doc" Then

               Dim oWord As Word.Application

               Dim oDoc As Word.Document

               Dim oBuiltInProps As Object

               Dim oCustomProps As Object

               Dim oProp As Object

               ‘Create Word Application

               oWord = CreateObject("Word.Application")

               ‘Open the document

               oDoc = oWord.Documents.Open(strWindowsFilePath)

               ‘Get custom properties collection

               oCustomProps = oDoc.CustomDocumentProperties

               ‘This will let the word know that the document should be saved

               oWord.ActiveDocument.Saved = False

               ‘Save changes in the document


               ‘Quit Word



    Your help greately appreciated!!!

  39. Ruben says:

    Thanks for this information, this was very useful to me, because I didn’t really want to use Word Interop to simply set and get some document properties. Using DSO is a much cleaner and leaner solution.

  40. Saju says:

    Hi Pachara,

    The error that you (and probably others facing problems with Office 2007) are facing might be due to registration of the dll. If you change the location of dsofile.dll, after extracting it, you need to register it using: regsvr32 [File path]dsofile.dll (in Windows -> Run). Hope this helps.

  41. Zal Ahmet says:

    I have been enocuntering a great deal of problems trying to get this example to work.  I hope someoner can help me.

    I have added a page to my website wherei have inserted all the code from the above example.

    I have downloaded the dsofile.exe and registered it to the server regsvr.exe file.  I have added the dll file to my bin folder, so i get Interop.DSOFile.dll in my bin folder.

    I ran the example and i upload a word document from my desktop to a folder location in my website.  I have given access rights to read and write to this folder so i hav no issues there.  When i click on the bowse button the location from my desktop is inserted into the file control.  when i click the load properties the proporties of the document are not populated.  And when i browsse to the folder location in the website to the file which has jsut been uplaoded the docmuent content disappears.  The only thing which appears as the content of the word document is the following line:


    I have used the uplaod method many times in previous work so i dont understand what is happening.  Also none of the document proerties exist in this uploaded document.

    Please help!

    Many thanks in advance


  42. Zal says:

    replying to my previous issue.

    I have resovled it i was not using the correct file uploader so i jsut changed it to the  Mediachase.FileUploader and it worked.

    yeppie doooooooooooooooo

    Happy programming

  43. Raam says:


    I tried to Extract Text from Excel File, after Open the Excel file ,some files get extracted but some other not. now i am using VS2005 language C#

    am new for Automation Process

  44. Prakash Tandukar says:

    I am using dso.dll (ver 2.1) to read ole file property. But we did not use com dso dll. Actually we re-wrote our won general dll(not com). Using our own dll, we were able to read ole property of doc file but we had problem reading docx property. Here is code snippet

    extern "C" TZDSOFILE_API IStorage* GetIStorage(char *filename)


    //Translate filename to Unicode.

    WCHAR wcFilename[1024];

    setlocale( LC_ALL, "" );

    int i = mbstowcs(wcFilename, filename, strlen(filename));

    setlocale( LC_ALL, "C" );

    wcFilename[i] = 0;

    IStorage *pStorage = NULL;

    HRESULT hr;

    // Open the document as an OLE compound document.

    hr = ::StgOpenStorageEx(wcFilename, NULL,



    return pStorage;


    return NULL;


    For doc file, this function successfully return IStorage but for docx file it returns null.

    Should we use different approach for docx file?

    Any idea…

    Highly Appreciated…

    Thank You

  45. Prakash Tandukar says:

    Sorry my previous function was wrong.  Here is the correct one

    extern "C" TZDSOFILE_API IStorage* GetIStorage(char *filename)


    //Translate filename to Unicode.

    WCHAR wcFilename[1024];

    setlocale( LC_ALL, "" );

    int i = mbstowcs(wcFilename, filename, strlen(filename));

    setlocale( LC_ALL, "C" );

    wcFilename[i] = 0;

    IStorage *pStorage = NULL;

    HRESULT hr;

    // Open the document as an OLE compound document.

    hr = ::StgOpenStorage(wcFilename, NULL,



    return pStorage;


    return NULL;


  46. Intel says:


    I have been trying to query the custom properties of a word document using DSOFile, but I cannot get it to work correctly.

    Do you have any example C# code, which would allow me to query and edit these custom properties?



  47. Urvish says:


    i m doing coding in C#.

    Is it possible to make Custom property (by programming)(word,excel,ppt)to hide from user or make read only – When user right click on file ,see custom property OR open file in word and see property.



  48. Ganesh says:


    I am using dsofile.dll to retrieve page count property for doc, xls and ppt documents.

    It provides default page count as 1 for all Word documents and 0 for all excel documents

    I need page count for Word document and excel sheet count for excel documents.

    //Sample Code

    int noofPages;

    DSOFile.OleDocumentPropertiesClass objDocument = null;


    (uploadedFile, true, dsoFileOpenOptions.dsoOptionOpenReadOnlyIfNoWriteAccess);

    noofPages = objDocument.SummaryProperties.PageCount

  49. Ganesh says:


    I am using dsofile.dll to retrieve page count property for doc, xls and ppt documents.

    It provides default page count as 1 for all Word documents and 0 for all excel documents

    I need page count for Word document and excel sheet count for excel documents.

    //Sample Code

    int noofPages;

    DSOFile.OleDocumentPropertiesClass objDocument = null;


    (uploadedFile, true, dsoFileOpenOptions.dsoOptionOpenReadOnlyIfNoWriteAccess);

    noofPages = objDocument.SummaryProperties.PageCount

    Pls let me know, How can i get the Page Count for the above documents

    Thanks and Regards


  50. Manjit says:

    Do anyone tried this in Vista. It does not seem to work in Vista. Please Suggest….

  51. vbwulf says:

    Using the lastest version of DSOFile.dll (2.1.2841), the old problem with modifying empty properties seems to be resolved.

    However, using dsofile to modify the properties of non-office-files [:♣SummaryInformation-streams of files on NTFS partitions], there seem to remain some bugs:

    1) The following properties can only be read, writing them returns error 450 (wrong number of arguments or invalid property assignment):



    2) The following properties can neither be read correctly (always return empty value), nor modified:


    -DateCreated (@modify returns error -2147467259)

    -DateLastSaved (@modify returns error -2147467259)

    Did anybody successfully manage to modify these properties @ non-office-documents?

  52. Archana says:

    Hi all,

    I have developed web application in asp.net 1.0 , In one of the report i have used Excel sheet to open ,it was giving access denied error  .

    So after giving ASPNET permission to folder(project folder) and to Excel Component in dcomcnfg file . Report in excel sheet  opened properly with no bugs in Windows XP

    But Even after giving same permission in all the neccessary place ( which i follwed in window XP), I am getting same error  as Access is denied in windows 2003 OS.

    With Exception as to set ASPNET permission to folder.

    Please help

    Thanks in Advance ,


  53. limo says:

    hi there,

    I am trying to read the file content i.e. text inside the word document to save it into a database, however it returns error saying : document.Template = null

    following is my code for the same :

    // dsofile operation to read word docs

                DSOFile.OleDocumentPropertiesClass mDoc = null;

                DSOFile.SummaryProperties docContent;

                //  DSOFile.CustomProperties dcContent;

                mDoc = new DSOFile.OleDocumentPropertiesClass();

                mDoc.Open(filePath, true, DSOFile.dsoFileOpenOptions.dsoOptionDefault);

                docContent = mDoc.SummaryProperties;

                strMsg = Convert.ToString(docContent.Template);


                strMsg = strMsg.Replace("r", "<br>");

                strMsg = strMsg.Replace("n", "<br>");

  54. rn says:

    I am able to set the properties into a given file. The problem is if I send that file via email to anybody, the properties as well as the custom properties I would have written are getting lost.

    My requirement is one shoudl be able to set the properties programatically and then they should persist across email exchanges.

    How do we handle this?

  55. jimelliott says:

    Context:  a Visual Basic 6 program to modify the custom properties of a Word document using

    dsofile.dll as described at http://support.microsoft.com/kb/224351

    Symptom:  attempting to add properties to a document that initially has no custom properties

    fails when calling dsofile.OleDocumentProperties.save.  Yes, I mean save not add!

    My assertion of a bug:  dsofile.dll treats files differently depending upon whether they have

    zero custom properties or at least one custom property present when the program runs.


    My program opens a Word document with

    Private m_oTargetDocProps As dsofile.OleDocumentProperties

    m_oTargetDocProps.Open filename, False, dsoOptionDontAutoCreate

    (reminder:  the file just opened has no custom properties)

    it attempts to add properties with

    m_oTargetDocProps.CustomProperties.Add propertyName, propertyValue

    This call to add does NOT cause an error.  Inspection of the object named m_oTargetDocProps

    with the Visual Basic object browser shows custom properties present (because the program added


    it attempts to save the properties into the file with m_oTargetDocProps.Save

    Save fails with Error -2147217147 (&H80041105): The command is not available because document

    was opened in read-only mode.

    Code workaround:  I know of no workaround in code unless one is inclined to build a modified

    dsofile.dll as suggested at http://www.codecomments.com/message813451.html

    Manual workaround:  use Word to add a custom property, the first and only custom property to

    the document.  I just named the property "dummy" with a value of "dummy text".

    Expedient suggestion:  have a program trap the situation just described and ask the human to

    use Word to add a dummy custom property.

    A related mystery:

    Ironically, if the above problem is avoided (because there was at least one custom property in

    the file) and if, according to Windows Explorer, the file is read-only, dosfile.dll is happy to

    ignore the file system’s read-only attribute and modify the custom properties!  How does that

    work?  Isn’t the file system supposed to prevent writing to a file with the read-only flag set?

    search words:

    bug dsofile.dll version 2.1

    modifies document properties even though Windows Explorer says file is read-only.

    dsofile.OleDocumentProperties.save fails with read only error even though file is writable

    empty dsofile.CustomProperty list

    Author can be reached by reversing the letters of my name:

    ttoillej at validatedsoftware dot com

  56. EasyAim says:

     It may be my imagination but I just upgraded from Windows XP to Windows 7 and the dsofile.dll fails to even display, much less change, the extended properties for JPG files. I had a great utility to change batches of photo properties with ‘Subject’ and ‘Comments’ to document them and now it is broke.

     Tell me again why we use Microsoft at all?