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 =
window.open('/NameBase.nsf/InsertForm?openform&IDDOC='
+id,'','top=150,left=3
50,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=420,height=180');

wintab.focus();"

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
a
Computed Field "NamesFiles" with the value @AttachmentsNames.

In the WebQuerySave event of the InsertForm you will put

@command([ToolsRunMacro];"A-Insert").

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 =
doc.createrichtextitem("RTFiles")
                     Set tempfile = contdoc.createrichtextitem("tempfile")
                     Dim o As NotesEmbeddedObject
                     Set o = contdoc.GetAttachment(contdoc.NamesFiles(0))
                     Call o.ExtractFile("c:Temp" + o.name)
                     Call tempfile.EmbedObject( EMBED_ATTACHMENT, "",
"c:temp" + o.name)
                     Kill "c:temp" + o.name
                     Call o.remove
                     If (rtitem.Type = RICHTEXT) Then
                          Call rtitem.AppendRTItem( tempfile )
                          Call doc.save(True,False)
                     End If
           End If
           Dim javascript As String
           javascript ="<script>window.opener.document.location.href=" &
"""javascript:_doClick('Refresh',this,null,null)""" &
";window.close()</script>"
           Print javascript

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

USER FEEDBACK TO THIS TIP

  • 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 last published in August 2001

Dig Deeper on Domino Resources

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com'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 ...

SearchEnterpriseLinux

SearchDataCenter

SearchExchange

SearchContentManagement

Close