Hi, We have a web-based application thru which the user is able to attach the attachment using FileUpload Control. So when user attaches the attachments no Richtextitem is created, but the attachments resides in $File. But these attachment have some special characters. So we are detaching the attachment to disk and renaming it and we need to reattach the updated attachment to the same document.
There is no problem if we create a new richtextitem and then embed attachment to it. All the above processing is being done thru an agent.
But the requirement is we shld not create any richtextitem and attach the attachment. It shld be same as the document recreated from without having the Richtextitem. Please go thru the code mentioned below and give me suggestion.
Dim session As NotesSession
Dim db As NotesDatabase
Dim doc1 As NotesDocument
Dim doc As NotesDocument
Dim fileobject As NotesEmbeddedObject
Dim nme As String
Dim array(4) As String
Dim rtitem1 As NotesItem
Dim a As Integer
Dim oldfilename As String
Dim ntview As NotesView
'have to feed in all the special characters in the array
array(0) = "\"
array(1) = "@"
array(2) = "#"
array(3) = "'"
array(4) = "&"
Set session = New NotesSession
Set db = session.CurrentDatabase
Set ntview=db.GetView("Invalid Characters")
Set doc=ntview.GetFirstDocument()
Set profdoc=db.CreateDocument
Dim nrtitem As New NotesRichTextItem( profdoc, "Comments" )
profdoc.form="LookUp"
profdoc.AgtName="StripSpecialChar"
Set item = profdoc.GetFirstItem( "Comments" )
Call profdoc.save(True, True)
While Not doc Is Nothing
msg3=""
Set doc1=ntview.GetNextDocument(doc)
result = Evaluate({@AttachmentNames}, doc )
fileName = result(0)
If filename <> "" Then
If doc.HasEmbedded Then
Set fileobject = doc.GetAttachment(filename)
oldfilename = fileobject.Name
nme = fileobject.Name
nme = Replace(nme, array, "")
filepath$= "D:\Archive\"& nme
Call fileobject.ExtractFile("D:\Archive\"+ nme)
Call doc.RemoveItem("$FILE")
Call doc.save(True, True)
Dim object As NotesEmbeddedObject
Dim rtitem As NotesRichTextItem
Set rtx = New NotesRichTextItem( doc, "test") ' this line to be removed
Set object = rtx.EmbedObject ( EMBED_ATTACHMENT, "",filepath$ ) ' this line to be removed
doc.SpecialChar="Y"
Call doc.Save( True, True )
Kill filepath$
End If
End If
Set item = profdoc.GetFirstItem( "Comments" )
If(doc.hasitem("VAccountNumber")) Then
msg3="Account ...."+doc.VAccountNumber(0)+"..........ComFolderType...."+doc.ComFolderType(0)
End If
msg1="Old File Name-----"+Cstr(oldfilename)
msg2=" New File Name--"+Cstr(nme)
If nrtitem.Type = RICHTEXT Then
If(msg3 <> "") Then
Call nrtitem.AppendText( msg3)
Call nrtitem.AddNewLine( 1 )
End If
Call nrtitem.AppendText( msg1)
Call nrtitem.AddNewLine( 1 )
Call nrtitem.AppendText( msg2)
Call nrtitem.AddNewLine( 1 )
End If
Call profdoc.save(True, True)
Call doc.save(True, True)
Set doc=doc1
Wend
end sub