logo

Control how attachments are removed

In a previous article I talked about using a combination of checkboxes and a WebQuerySave agent to produce an alternative method of removing attachments from a document. Thus, getting rid of the horrible check-boxes that domino automatically generates:

Image

Whilst that method worked fairly well, I have since learnt of a much easier/better/quicker way to do this.

All you need to do is create your own set of check-boxes that all share the same name: %%Detach.

Easiest way to do this is to use a Computed-Text area (you can't use a field as they don't allow the % character in the name). The formula should be along the lines of:

@If(!@Attachments; @Return(""); "");
@If(@IsDocBeingEdited;
"<p>Remove attachments here:<br>" +
@Implode("<input type=\"checkbox\" name=\"%%Detach\" value=\""+@AttachmentNames+"\">"+@AttachmentNames; "<br>");
"<p>View attachments here:<br>" +
@Implode("<a href=\"" + @Text(@DocumentUniqueID) + "/$file/" + @AttachmentNames + "\">"+@AttachmentNames + "</a>"; "<br>"))

What does this do? First thing is to see if there are any attachments on the document. If not then it just returns an empty string (""). Otherwise, it checks if the document is in edit mode. If so, it creates a delete checkbox for each attachment with a value the same as the file's name. If the document is being read it simply creates a set of links that the user can use to open or save the file from.

Now, when the document is submitted, domino takes control of the deletion of all the files that you selected automatically. Isn't it a clever little thing...

Here is an example of this method being used in a database available for download here. Firstly in read mode:

Image

and in edit mode:

Image

How you make it look and where you place the HTML is totally down to you. No longer do you have to suffer the awful way Iris does it ;-) The last thing to do is to hide the "Iris" part. You could use the <noscript> method, but I prefer this one as it is a lot cleaner.


Feedback

  1. Different Icons for the attachments

    Hello Jake,

    I have read your article about the control of attachments and I was impressed. I also hate the style how domino displays attachments and I've looked for an alternative and found it on your side. Thank you very much. I've integrated your mechanism in an application and it works like a charm.

    Now I have a question. I want to display different symbols before the link of the attachment. For example: If the document has an attachment with the extension '.txt' I want to display the viewicon 'vwicn020.gif'. If the document has an attachment with the extension '.doc' I want to display the Wordicon 'vwicn142.gif'.

    At the moment I have the following code for the computed text field:

    ************************************* tmpASum:=@Text(@Round((@Sum(@AttachmentLengths)/1024);0,01)) + " Kbytes"; tmpALen:=@Text(@Round((@AttachmentLengths/1024);0,01)) + " Kbytes"; tmprepl:= ".html":".htm":".txt":".zip":".exe":".gif":".jpg":".bmp":".doc":".xls":".wav":". mid":".midi"; tmprwith := "vwicn070.gif":"vwicn070.gif":"vwicn020.gif":"vwicn051.gif":"vwicn159.gif":"vwic n013.gif":"vwicn013.gif":"vwicn013.gif":"vwicn142.gif":"vwicn141.gif":"vwicn015. gif":"vwicn015.gif":"vwicn015.gif"; @If(!@Attachments;@Return("");""); @If(@IsDocBeingEdited; "<br><br><table border=1 bgcolor=\"#0000aa\" cellspacing=0 cellpadding=5><tr><td>"+ "<font size=2 face=\"arial\" color=\"#ffffff\">"+ "Attachments l&ouml;schen:"+ "</font><font size=1 color=\"#555555\">"+ @Implode("<table border=0 bgcolor=\"#eaeff0\" width=300 cellpadding=5>"+ "<tr><td><input type=\"checkbox\" name=\"%%Detach\" value=\""+@AttachmentNames+"\">"+ "<font size=2 face=\"verdana\">"+@AttachmentNames+ "<br></td></tr></table>")+ "</td></tr></table>"; "<br><br><table border=1 bgcolor=\"#0000aa\" cellspacing=0 cellpadding=5><tr><td>"+ "<font size=2 face=\"arial\" color=\"#ffffff\">"+ "Attachments ansehen ("+tmpASum+") :"+ "</font><font size=1 color=\"#555555\">"+ @Implode("<table border=0 bgcolor=\"#eaeff0\" width=300 cellpadding=5>"+ "<tr><td width=200>"+ @If(@Contains("." + @Right(@AttachmentNames;"."); @Implode(tmprepl));""; @Replace("." + @Right(@AttachmentNames;"."); tmprepl; "<img src=\"/icons/" + tmprwith + " \"border=0 width=16 height=11 hspace=3>")) + "<a href=\"" + @Text(@DocumentUniqueID) + "/$file/" + @AttachmentNames+"\">"+ "<font size=2 face=\"arial\"><b>[ "+@AttachmentNames+" ]</b></font></a></td>"+ "<td width=10></td>"+ "<td width=150 align=right><font size=1 face=\"verdana\">"+tmpALen+"</font></td><tr></table>")+ "</td></tr></table>") ************************************* This works so far. But I try to find a solution for unrecognised attachments.

    1. Re: Different Icons for the attachments

      Probably out of date now, but I have several gif files in the database, each of which has the name of a file extension.

      e.g.

      an icon representing .gif files is named 'gif' an icon representing .jpg files is named '.jpg' and aliased '.jpe'

      Then I use the following in as part of a formula.

      "<tr><td width=\"10\"><img onerror=\"this.src=\'../***\'\" src=\"../"+@Right(@Text(@AttachmentNames);".")+"\"></td><td width=\"10\"><input type=\"checkbox\" name=\"%%Detach\" value=\""+@AttachmentNames+"\" class=\"line1\"></td><td><a href=\"" + @Text(@DocumentUniqueID) + "/$file/" + @AttachmentNames+ "\">"+@AttachmentNames + "</a></td><td>" + @Text(@Round(@AttachmentLengths/1024)) + " (Kbytes)</td></tr>"

      Note : onerror=\"this.src=\'../***\'\" this javascript makes a default icon appear '***' from the image resources, if no other icon is found.

      Hope this helps if you still needed a way of displaying an icon if none found.

    2. Re: Different Icons for the attachments

      Less sophisticated, but with icon showing for all attachments not referenced.

      @If(!@Attachments; @Return("<tr><td colspan=4>There are no attachments on this document.</td></tr>"); ""); @Implode("<tr><td width=10><img src=/icons/vwicn" + @If( @Right(@AttachmentNames;".")="doc"; "142"; @Right(@AttachmentNames;".")="dot"; "142"; @Right(@AttachmentNames;".")="xls"; "141"; @Right(@AttachmentNames;".")="xlt"; "141"; @Right(@AttachmentNames;".")="txt"; "020"; @Right(@AttachmentNames;".")="zip"; "051"; @Right(@AttachmentNames;".")="exe"; "159"; @Right(@AttachmentNames;".")="gif"; "013"; @Right(@AttachmentNames;".")="jpg"; "013"; @Right(@AttachmentNames;".")="bmp"; "013"; @Right(@AttachmentNames;".")="html"; "070"; @Right(@AttachmentNames;".")="htm"; "070"; @Right(@AttachmentNames;".")="wav"; "015"; "006") + ".gif></td><td></td><td> <a href=\"" + @Text(@DocumentUniqueID) + "/$file/" + @AttachmentNames+ "\">" + @AttachmentNames + "</a></td><td>" + @Text(@Round(@AttachmentLengths/1024)) + " (KB)</td></tr>";@NewLine)

      Show the rest of this thread

  2. Nice

    Hey Jake - Great site, I was just trying to figure out how to do this.

    S

  3. Problem with deleting attachments

    Hi,

    I'm trying to write a cross client(Notes Client and browser) attachment system and have used this article to incorporate the code to delete attachments and it (so almost) works!

    The problem I have occurs in this scenario:- - a user attaches a file in Notes Client into an RTF field and saves the document. - User with web browser edits the document and checks the box to delete the attachment and saves the document. Opening the document in the browser in read mode shows the file has been deleted. Cool - Notes Client user goes into the document and can still see the file attachment in the RTF field. It looks like the file itself has been removed as the attachment has no properties but "residue" is left in the RTF field that doesn't get auto deleted. I'll look into some LotusScript code to delete the attachment from the RTF and see if that works and let you guys know....

    Cheers, Chris.

    1. Well that's just great....

      According to this:-

      http://www.notes.net/46dom.nsf/55c38d716d632d9b8525689b005ba1c0/ee7265887cce110a 852569b200542be4?OpenDocument&Highlight=0,API,attachment,remove

      The $file (file attachment) field and the file icon bitmap in the RTF are 2 separate things. Great! Not.

      Only solution I can think of is to have a separate field to emulate the %%DETACH field but called something else (like ToBeDeleted) so that Notes can't cock up the deletion. Next step is to detach all files to a temp directory on the server file system using the code on codestore.net. Then delete the RTF field. Then re-attach the files to a newly created RTF excluding the filenames in the ToBeDeleted field.

      What an almighty load of rubbish that is! Of course if there is a better way, then please please let me know!

      Cheers, Chris.

  4. thanks for your info

    Thanks for your info regarding file attachments deletion on browser.

    Bye from Italy

  5. attachments

    Thank you for your very good articles and sorry for my bad english. I have a question about displaying attachments nicly in a table with more than one column: sometimes, I have many attachments in my documents and i want to have a dynamic table with changable column for displaying them, could you perhaps help me.

    Thanks a lot

      • avatar
      • MK
      • Thu 19 Dec 2002

      Re: attachments

      Hi

      this is a nice workout, thanks for your help

  6. attachments

    To Jake and all the guys....thanks a lot...i also used your ideas for a project that i'm working on and it worked..!!!...really appreciate it....thanks again...:P

    1. Re: attachments

      Hi I have an multiple attachments stored on the document in the web.I want to remove all attachments except the recent attachment when i click on the button.

      coud you please help me in that.

      Thanks Chandra.

      Show the rest of this thread

    • avatar
    • laurens
    • Fri 14 Nov 2003

    same thing, but sorting attachments a-z

    two minor improvements to this lovely code:

    1) using R6 @sort code, you can sort the attachments a-z 2) turning the names of the attahments in to links, it is easier to check what the file contains you considering deleting. E.g. you have 5 pictures uploaded, but don't remember which is which. Clicking on the link opens the attachment in a new browser window.

    AS:=@If(!@Attachments; @Return("");@Sort(@AttachmentNames)); @If(!@Attachments; @Return(""); "Select Attachments or Pictures to be deleted:" + @Implode("<input type=\"checkbox\" name=\"%%Detach\" value=\""+AS+"\"><a href=\"" + @Text(@DocumentUniqueID) + "/$file/" + AS + "\" target=\"_blank\">"+AS + "</a>"; "<br>"))

  7. I wan't the attachment placed in a field...

    Hello

    Could you please help me out here cause I'm stuck. I wan't to: - be able to upload more then one attachment at one time still not use more than one upload control (make a list...). - have the attachments submitted to a Rich text field rather than as v2-attachments.

    Possible?

    Thanks Ove

  8. Sync between web atts and notes

    Hi,

    I really did like the article on managing attachments from the web, clever stuff.

    However, I run into problems when trying to move attachments uploaded from the web to rich-text fields. All seems to work fine from the web, but the rich text field keeps orphaned icons to attachments that already have been removed from the document via the web. Is there any way to correctly synchronize the web actions with the actual storage of the attachments in a rich text field in Notes?

    Thanks!

    Ed

    1. Re: Sync between web atts and notes

      Hi, I'm having the same problem to sync the web action to the notes actions. Can anybody please help me?

      Show the rest of this thread

  9. I can't hide the attachment

    hi I only use one fileupload controler to upload more than one file.and I use a button to add the file url to a multiple value list box .when the document was saved,I used an agent to EmbedObject all the file to a Rich Text Field. when I open the document from the view,the horrible check-boxes that domino automatically generates does not hidden now. I have been searching and experimenting how to fix this, but did not find a solution for this. Hope you have one.

    Thanks in advance all ready,

    yanli wu

    • avatar
    • Caroline
    • Tue 2 Nov 2004

    Automatically deleting existing attachment

    I have a requirement to only have 1 attachment per document, but that the user can change the attachment. I figured that using the delete method described to only delete the existing attachment if a new one is being uploaded was a good plan. I have the following JavaScript in the onSubmit to detect if we are uploading a new attachment, and to write to a field that effectively deletes the existing attachment. However, you have to click on the save button twice for it to work. Any clever refinement ideas?

    var newfile = document.forms[0].NewFile.value; var del; if (newfile =="") { del = ""; } else { start = newfile.lastIndexOf("\\") + 1; end = newfile.length; file_picname = newfile.slice(start,end);

    del = '<input type="checkbox" name="%%Detach" CHECKED value="'+file_picname+'">'+file_picname; alert (del); } document.forms[0].DeleteAttachments.value = del

    Caroline

      • avatar
      • Caroline
      • Tue 2 Nov 2004

      Re: Automatically deleting existing attachment

      Got it!!

      If you only want 1 attachment per doc, and if you want people to override the existing attachment simply by uploading another, here is the plan:

      In the onSubmit, put:

      var newfile = document.forms[0].NewFile.value; // NewFile is the ID of the File Upload Control

      if (newfile !="") { // there is a new file to upload

      existingFile = document.forms[0].FileName.value; // see FileName field below if (existingFile != "") { // remove existing file document.forms[0]["%%Detach"].value= existingFile // see %%Detach field below } } // end if new file is nothing

      Pu this as computed text at the top of the form:

      "[<INPUT TYPE=HIDDEN NAME = \"FileName\" VALUE=\"" + @Text(@AttachmentNames) + "\">]"

      This is so JavaScript can access the existing file attachment name. At the bottom of the form, hidden, put a field called "FileName" so Domino doesn't have kittens when the doc is saved. Make it editable with no default.

      Put in another bit of computed text on the form to define the detach field:

      "[<input type=\"hidden\" name=\"%%Detach\" value=\"\">]"

      Tested on IE6 and Notes5

      CAroline

      Show the rest of this thread

    • avatar
    • Lois
    • Thu 24 Feb 2005

    attachment

    I used your attachment code and it works great! But my users want a way to put descriptions for each file. Do you know of a way to do this?

  10. Broken in R7?

    It seems this work around has been broken in R7: http://bob-obringer.com/A557B7/blog.nsf/dx/12142005114901DOMNW8.htm

    - Johan http://johankanngard.net

  11. Deleted Attachment

    Is it possible to make a view for deleted attachmebnts.

    1. Re: Deleted Attachment

      How about using the inotes control in your app to do all the file management.

      http://thehojusaram.blogspot.com/2006/09/domino-activex-inotes-file-upload.html

Your Comments

Name:
E-mail:
(optional)
Website:
(optional)
Comment:



Navigate other articles in the category "Forms"

« Previous Article Next Article »
Buttons with Keyboard Shortcut   Creating a printer friendly page

About This Article

Author: Jake Howlett
Category: Forms
Hat Tip: Sylvain Goutouly
Keywords: attachment; file; remove; detach;

Options

Feedback
Print Friendly

Let's Get Social


About This Website

CodeStore is all about web development. Concentrating on Lotus Domino, ASP.NET, Flex, SharePoint and all things internet.

Your host is Jake Howlett who runs his own web development company called Rockall Design and is always on the lookout for new and interesting work to do.

You can find me on Twitter and on Linked In.

Read more about this site »