I am using Microsoft's DSOFile library to work with extended file attibutes and I'm having problems under Vista with non-OLE files.
The following C# code simply reads any custom attributes that are attached to a file:
private void readCustomProperties(string fileName)
{
DSOFile.OleDocumentPropertiesClass documentProperties = new OleDocumentPropertiesClass();
documentProperties.Open(fileName, false, dsoFileOpenOptions.dsoOptionOpenReadOnlyIfNoWriteAccess);
foreach (DSOFile.CustomProperty customProperty in documentProperties.CustomProperties)
{
Debug.WriteLine(customProperty.Name + " : " + customProperty.get_Value().ToString());
}
documentProperties.Close(false);
}
This code works fine on Vista if I open an OLE document such as a Microsoft Word document. However if I open a non-OLE file such as a PDF then on the first time I go through the code it works file. If I then open the same file again, I get an exception thrown when accessing the documentProperties.CustomProperties:
The handle is invalid. (Exception from HRESULT: 0x80070006 (E_HANDLE))
I then get this exception on every subsequent attempt. The really wierd thing is, that if I run my app with elevated priviliges or disable UAC then it works perfectly fine. It also works fine on Windows XP and 2000.
I realise that Microsoft states that they do not support using DSOFile with non-OLE file types, but the fustrating thing is that it does work with UAC turned off. Note that it doesn't matter where the file is physically located, I don't need admin access to read or modify the file.
Has anyone used DSOFile in this way in Vista successfully?