Trying to parse a Word document, receiving COM exceptions

0

This is my code to read custom properties from a file. This works on all file types. but shows System.Runtime.InteropServices.COMException (0x80004005):

on word document 2013

Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL)) System.Runtime.InteropServices.COMException

on word document 2003

(0x80030005): Access Denied. (Exception from HRESULT: 0x80030005 (STG_E_ACCESSDENIED))

Also is the DeleteCustomPropertyThroughDSO function is correct or not? I am using DSOFile.dll x86 version.

private static JObject ReadCustomPropertiesThroughDSO(string fileName)
    {
        JObject Properties = new JObject();
        OleDocumentProperties file = new OleDocumentProperties();
        try
        {
            file.Open(fileName, false, dsoFileOpenOptions.dsoOptionDefault);
            foreach (CustomProperty p in file.CustomProperties)
            {
                Properties.Add(p.Name, p.get_Value().ToString());
            }
            file.Save();
            file.Close();
        }
        catch (Exception ex)
        {
            Console.WriteLine("Exception in --> ReadCustomPropertiesThroughDSO: " + ex);
            return null;
        }
        return Properties;
    }

private static string DeleteCustomPropertiesThroughDSO(string fileName)
    {
        OleDocumentProperties file = new OleDocumentProperties();
        try
        {
            file.Open(fileName, false, dsoFileOpenOptions.dsoOptionDefault);
            foreach (CustomProperty p in file.CustomProperties)
            {
                p.Remove();
            }
            file.Save();
            file.Close();
        }
        catch (Exception ex)
        {
            Logger.Write_Log("Exception in -->  DeleteCustomPropertiesThroughDSO: " + ex);
            return FAILURE;
        }
        return SUCCESS;
    }

I will be happy if you direct me in a correct direction. Thank you in advance. My Question is, DSOFile.dll works for xlsx and pptx. The problem is only for Word documents.

c#
custom-properties
dsofile
asked on Stack Overflow Jan 28, 2019 by ARVINTH RAAJ K K BIT • edited Jan 28, 2019 by Maximilian Burszley

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0