Insert various file attachments on the Web

This tip allow you to insert various files in a document and refresh it for each upload in a Web aplication.

You Can View User Feedback To This Tip

This tip allow you to insert various files in a document and refresh it for each upload in a Web aplication.

All the files will be inserted in a Rich Text Field which is named "RTFiles".

The name of the database is "NameBase.nsf"

You need Two Forms and a view :
- the first form is the default form use by the document (Name = DefaultForm).
- the second form is use for insert the files (Name = InsertForm).
- A view named "(ID)" sort this the field IDDDOC of DefaultForm.

The DefaultForm is compose by yours fields, a Rich text field which name is "RTFiles" and a Computed Field wich name is "IDDOC" with the @DocumentUniqueID of the document.

In the DefaultForm you must create an action which code javascript is:

" var wintab;
var id = document.forms[0].IDDOC.value;
wintab ='/NameBase.nsf/InsertForm?openform&IDDOC='


This action open a new window with the form InsertForm and in the Query_String you have the Id of the document which will receive the files attachments.

In the InsertForm You must create a File Upload, A Field Query_String, A computed Field with the name "IDDOC" and the code :

@Right(Query_String;"&IDDOC="), a field SaveOptions with the value "0" and
Computed Field "NamesFiles" with the value @AttachmentsNames.

In the WebQuerySave event of the InsertForm you will put


And the code for the A-Insert agent is :

           Dim s As NotesSession
           Dim db As notesdatabase

           Set s = New NotesSession
           Set db = s.currentDataBase

           Dim contdoc As notesdocument
           Set contdoc = s.DocumentContext
           Dim iddoc As notesitem
           Set iddoc=contdoc.getfirstitem("iddoc")

           Dim view As notesview
           Dim doc As notesdocument
           Set view=db.getview("(ID)")
           Call view.refresh()
           Set doc = view.getdocumentbykey(contdoc.iddoc(0))

          If contdoc.Hasembedded Then
                     Dim tempfile As Variant
                     Dim RTITEM As Variant
                     Set rtitem=doc.getfirstitem("RTFiles")
                     If (rtitem Is Nothing) Then Set rtitem =
                     Set tempfile = contdoc.createrichtextitem("tempfile")
                     Dim o As NotesEmbeddedObject
                     Set o = contdoc.GetAttachment(contdoc.NamesFiles(0))
                     Call o.ExtractFile("c:Temp" +
                     Call tempfile.EmbedObject( EMBED_ATTACHMENT, "",
"c:temp" +
                     Kill "c:temp" +
                     Call o.remove
                     If (rtitem.Type = RICHTEXT) Then
                          Call rtitem.AppendRTItem( tempfile )
                     End If
           End If
           Dim javascript As String
           javascript ="<script>window.opener.document.location.href=" &
"""javascript:_doClick('Refresh',this,null,null)""" &
           Print javascript

This agent will insert the file upload in the RTFiles RixhTextField and Refresh the document.


  • This tip only works on Windows or Linux platforms. The reason for this is that the 'WebQuerySave'-agent called 'A-insert' uses the method 'EmbedObject' of the NotesRichTextItem. This method is not supported on MacIntosh, OS/2 and UNIX operating systems.—Ronald van Puijenbroek
  • This tip works great !!! but..
    if 2 users tries to attach a file with same name concurrently, it might produce error message because the file is being extracted to the server's hard drive before re-attaching it to the current document. I understand that this situation would be uncommon, but the website that caters a large number of users might face this problem.—Ravi

This was first published in August 2001

Dig deeper on Domino Resources



Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:



  • iSeries tutorials's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...