这是我从文件中读取自定义属性的代码。这适用于所有文件类型。但显示System.Runtime.InteropServices.COMException (0x80004005):
2013年word文档
未指定的错误(来自 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 文档。