I tried to write a function using NotesRichTextNavigator to launch a file stored in a richtext field. It works well if the file was attached into the richtext once. If users attached the file into the richtext more then one time and the first attached file removed, then the function won’t work. Any solution?
I’m not sure what you mean that “the function won’t work.” First, which function are we talking about? May we see the relevant portion of code? In what way does it not work? Does it error out? If so what’s the error message? If not, exactly what does it do that’s not what you want?
Please think about what information we will need to help you.
Dim uiws As New NotesUIWorkspaceDim uidoc As NotesUIDocument
Dim doc As NotesDocument
Dim body As NotesRichTextItem
Dim rtNav As NotesRichTextNavigator
Dim file As String, tmp As String
tmp = "C:\Temp"
Set uidoc = uiws.CurrentDocument
Set doc = uidoc.Document
Set body = doc.GetFirstItem(“Body”)
file = Ucase(uidoc.FieldGetText(“FileList”))
Set rtNav = body.CreateNavigator
If rtnav.FindFirstElement(RTELEM_TYPE_FILEATTACHMENT) Then
Do
obj = rtnav.GetElement
If Ucase(obj.Source) = file Then
FileName = tmp & obj.Source
'Save file
obj.Extractfile (FileName)
End If
Loop While rtnav.FindNextElement(RTELEM_TYPE_FILEATTACHMENT)
End If
The obj.Extractfile(Filename) doesn’t work. Error is about could not locate File.
You seem to be saying that you get an error that says “coud not locate file” when you call Extractfile method. I don’t believe this is the case, since this method does need to find a file to work. I suspect you’re actually getting the error later on in your code when you try to use the file that you extracted. It would appear that the filename is different from what you thought it would be.
There is no “doesn’t work.” There’s you describing exactly what happened. Did it create a file or not?
There is no “error is about.” There’s you telling us exactly the complete text of the message. Even if it’s not in English.
Please use the Notes debugger to find out what line the error is actually occurring on, and to find out the values of important variables such as Filename.
Please see my first question. I didn’t say that the function doesn’t work at all. It works fine when the attachment had been attached one time. However, I don’t know why, some of the users attached the same file to the document and removed the first attachment, then the error occurs. The precise error is “Could not locate attached file filename”. And no, the file didn’t save. I did use the debugger to locate the error. And it occurs at obj.Extractfile (FileName).
This is probably a bit late but check with the debugger to see if the object you are working on has a file size of ZERO. This seems to coincide with what I have been encountering in the last day or so when an attachment has been deleted from the NotesDocument and there seems to be something like an attachment stub left over.
Do a check on the object’s size and skip it if obj.FileSize < 1.
Perhaps there is some problem with ExtractFile. However, the conditions to bring it about must be more complex than you are telling us about. I created a sample database with a simple form – a Subject field and a rich text Body field – and created three sample documents – one with an attachment, one with two copies of the same attachment, and one where I added two copies of the same attachment, then deleted the original. Also tried this last scenario where I saved the document first with one attachment, then edited it, added a second copy of the same file, and deleted the original.
In all cases, the following code ran without an error and created files with the same names as the original files (although the @AttachmentNames function shows system-created unique names for the second copies of the same filename).
I’m usign 6.5.3, but looking at the SPR database, it doesn’t appear that this problem has already been reported and corrected. Send me email at us.ibm.com and I’ll send you the sample database for you to try.
Dim session As New NotesSession
Dim db As NotesDatabase
Dim coll As NotesDocumentCollection
Dim doc As NotesDocument
Dim rti As NotesRichTextItem
Set db = session.CurrentDatabase
Set coll = db.UnprocessedDocuments
Set doc = coll.GetFirstDocument( )
Set rti = doc.GetFirstItem("Body")
Forall obj In rti.EmbeddedObjects
Print "filename = " & obj.Source ' prints original name, not system-generated unique name.
obj.ExtractFile("C:\temp\" & obj.Source)
End Forall
Maybe you should try it this way instead of using the NotesRichTextNavigator.