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.
User contributions licensed under CC BY-SA 3.0