Tip

Insert various file attachments on the Web

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

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
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
Sort by: OldestNewest

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:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.