About This Code
Brief Description:
Display Attachment Images on the Web
Contributor:
Greg Wlodarczyk
Notes Version:
R6.x, R5.x
Last Modified:
12 Jul 2006
OpenNTF Disclaimer
All of the program code and information presented in the OpenNTF.org Code Bin are provided "as-is", and should be used at your own risk. OpenNTF.org make no express or implied warranty about anything in the Code Bin, and OpenNTF.org will not be responsible or liable for any damage caused by the use or misuse of anything from this site. OpenNTF.org makes no guarantees about anything. Please thoroughly test all of the knowledge and code you find here before you attempt to use them in your production environment.
Code / Description
- The following formula will display the associated attachment image based on the extension of the attachment
- If the there is no associated attachment image the default file.gif image will be displayed
- Add the gifs from the attached gifs.zip file as Shared Resources - Images
Usage / Example
HTML Head Content - @NewLine + "<base href=\"http://" + Server_Name + "/" + @WebDBName + "/\" />" ;
Attachment Computed Text Field:
@If(!@Attachments; @Return(""); "");
AttName:=@AttachmentNames;
AttLink:="<a href="+ @Text(@DocumentUniqueID) +"/$File/" + @ReplaceSubstring(AttName;" ";"%20") + "><img onerror=\"this.src='file.gif'\" src="+@LowerCase(@Right(AttName;3)) +".gif alt=\"\" border=\"0\" > " +AttName + "</a>";
@Implode(AttLink;"<br/>")
Code Attachments
Comments
Posted by Daniel Hasa on 11/26/2006 04:46:23 AMNice - also have a look at this:
Hi
You can solve this also with the 'standards'. Just paste this code into a computed field. The missing pdf and zip could be combined with your code
tmprepl:= "html":"htm":"txt":"zip":"exe":"gif":"jpg":"bmp":"tiff":"tif":"doc":"xls":"wav":"mid":"midi":"vsd":"ppt":"pps";
_vAttDef := "/icons/vwicn001.gif";
tmprwith := "/icons/" + ("vwicn070.gif":"vwicn070.gif":"vwicn058.gif":"vwicn051.gif":"vwicn159.gif":"vwicn013.gif":"vwicn013.gif":"vwicn013.gif":"vwicn013.gif":"vwicn013.gif":"vwicn142.gif":"vwicn141.gif":"vwicn015.gif":"vwicn015.gif":"vwicn015.gif":"vwicn145.gif":"vwicn143.gif":"vwicn143.gif");
_varToDel := "<input type=\"checkbox\" name=\"%%Detach\" value=\""+@AttachmentNames+"\">remove";
tmpASum:=@Text(@Round((@Sum(@AttachmentLengths)/1024);0.01)) + " Kb";
tmpALen:=@Text(@Round((@AttachmentLengths/1024);0.01)) + " Kb";
_vAttList := @AttachmentNames;
_vAttEnd := @LowerCase(@RightBack(_vAttList;"."));
_vAttIcons := @Replace(_vAttEnd;tmprepl;tmprwith);
_vAttDisp := "";
_vAttBuild := @For(n:=1;n<=@Attachments;n:=n+1;
_vAttDisp := @Trim(_vAttDisp:("<img src=\"" + @If( @IsMember(_vAttEnd[n];tmprepl) ; _vAttIcons[n];_vAttDef)+ "\" border=\"0\">")));
@If(!@Attachments; @Return("<tr><td colspan=\"2\">There are no attachments in this document.</td></tr>");"");
@Implode("<tr><td><a href=\"/" +@WebDbName +"/"+ @Text(@DocumentUniqueID) + "/$file/" + @AttachmentNames+ "\" target=\"NewWindow\">"+_vAttDisp+" " +@AttachmentNames + " (" + tmpALen + ")</a></td><td align=\"right\">" + @If(@IsDocBeingEdited;"<!--Del //-->"+_varToDel;" ") + "</td></tr>";@NewLine) +
"<tr><td colspan=\"2\">Total size: " + tmpASum + @NewLine+
"</td></tr>"