Tip

Delete file attachments on the Web

This tip allows you to delete several files attachments included in a rich text item. You can use it with the tips "Insert various files attachments on the Web."

This tip works only on NT and Linux server.


The name of the database is "NameBase.nsf".

You need Two Forms and a view:
- the first form is the default form used by the document (Name = DefaultForm).
- the second form is used for deleting t>he files (Name = DeleteForm).

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

In the DefaultForm, you must create an action "Delete Files" which the JavaScript code is:

 var wintab; var id = document.forms[0].IDDOC.value; wintab = window.open('/NameBase.nsf/DeleteForm?openform&IDDOC=' +id,'','top=150,left=350,toolbar=no,location=no,directories=no, status=no,menubar=no,scrollbars=no,resizable=no,width=420,height=180'); wintab.focus();

This action opens a new window with the form DeleteForm, and in the Query_String, you have the Id of the document in which you want delete the file attachments.

In the DeleteForm, you must create:
- a Field Query_String = Query_String,
- a computed Field with the name "IDDOC" and the code is @Right(Query_String;"&IDDOC=")
- a field SaveOptions with the value "0".
- a multivaluated list field named "DelFiles" which the formula selection is
res := @DbLookup("":"NoCache";"":"";"(ID)";iddoc;2);@If(@IsError(res) | res =""; ""; res);

DelFiles is used for the selection of the files that the user want delete.

In the WebQuerySave event of the DeleteForm, you will put :

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

And the code for the A-Delete 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 view As notesview Dim doc As notesdocument Set view=db.getview("(ID)") Call view.refresh() Set doc = view.getdocumentbykey(contdoc.iddoc(0)) '********** Delete all the files selected**** Dim delfiles As notesitem Set delfiles=contdoc.getfirstitem("DelFiles") Dim rtitem As Variant Set rtitem = doc.GetFirstItem( "RTFiles" ) Dim object As Variant Forall o In delfiles.values If ( rtitem.Type = RICHTEXT ) Then Set object = rtitem.GetEmbeddedObject(o) Call object.Remove Call doc.Save( True, True ) End If End Forall '*********Refresh Document Principal and close window ******** 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 delete the files selected with the "DelFiles" Field and refresh the current document.

This was first published in September 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.