OLE Document Reader crashes office applications

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am using the DSO OLE Document Properties Reader 2.0 to update custom
properties in office files. (i.e. a word document)

After updating a couple of times, the word document becomes corrupted.

I am using the following code to open the file and update the custom
document properties.

mobjDocument = New DSOFile.OleDocumentPropertiesClass
mobjDocument.Open(FileName, False,
DSOFile.dsoFileOpenOptions.dsoOptionOnlyOpenOLEFiles)


Once the document is opened, update the fields

UpdateData("address1", "1 Homes Palce")
UpdateData("address2", "Reading")
UpdateData("BusinessGroup", "Unknown")



Private Sub UpdateData(ByVal Name As String, ByVal Value As String)

Dim objCustProp As DSOFile.CustomProperty
Dim lngIndex As Long
Dim blnFound As Boolean = False
Dim objValue As Object

Try
For lngIndex = 0 To mobjDocument.CustomProperties.Count - 1
If mobjDocument.CustomProperties(lngIndex).Name = Name Then
objCustProp = mobjDocument.CustomProperties(lngIndex)
objCustProp.Value = Value
blnFound = True
Exit For
End If
Next
Catch ex As Exception
Logging.WriteToSpecifiedFile("Error Finding Data : " &
ex.Message, LogFileName)
End Try

If Not blnFound Then
Try
objValue = CStr(Value)
objCustProp = mobjDocument.CustomProperties.Add(Name,
objValue)
Catch ex1 As Exception
Logging.WriteToSpecifiedFile("Error Adding Data : " &
ex1.Message, LogFileName)
End Try
End If

End Sub


Once the details have been updated, i save the file and close the file

mobjDocument.Save
mobjdocument.Close(True)
mobjDocument = Nothing


The following article says the bug is the product of a very old conflict:
ANSI/Unicode compatibility. but this seems to be appropriate to version 1.4
of the OLE Reader and not 2.0.

http://msdn.microsoft.com/library/default.asp?url=/archive/en-us/dnaraskdr/html/askgui07312001.asp

I basically need to update the word custom properties on a regular basis
without corrupting the office document.
 
Hi,

I found that trying to update or add attributes with empty strings had the
effect that you mention.
 
Back
Top