这是我的代码,用于从文件读取自定义属性。这适用于所有文件类型。但显示System.Runtime.InteropServices.COMException (0x80004005):
在Word文档2013上
未指定的错误(HRESULT的异常:0x80004005(E_FAIL))System.Runtime.InteropServices.COMException
在Word文档2003上
(0x80030005):访问被拒绝。 (来自HRESULT的异常:0x80030005(STG_E_ACCESSDENIED))
DeleteCustomPropertyThroughDSO
函数是否正确?我正在使用DSOFile.dll x86版本。
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;
}
如果您的方向正确,我会很高兴。先感谢您。 我的问题是,DSOFile.dll适用于xlsx和pptx。该问题仅适用于Word文档。