Attaching and importing image files in one click
2011-09-22 10:29
357 查看
Suppose you want to send an image to someone, and to save your recipient the extra step of having to launch or open the file attachment to preview the image, you want to display the image in the document and attach the image file for downloading. Attaching and importing images is usually a two-step process: First, you attach the image by choosing File - Attach, and then to import the image into a document, you choose File - Import.
But no longer-you can attach and import image files in one step by:
Creating three fields on a form: a field to host the file attachment, a field to display the image, and another to display the file name.
Creating a hotspot button that attaches and displays the image file with one click.
We'll also tell you how to remove the image and file attachment from the document with one click.
Creating the form fields
Create or modify a form, adding the following fields:
Back to top
Creating the hotspot button
Now create a hotspot button and label it Attach & Display. Then copy and paste the following code into the programmer's pane:
The formula does the following:
Checks whether or not the document is in edit mode.
If the document is in edit mode, the formula attaches the image to the img field using @Command([EditInsertFileAttachment]).
After attaching the image, the formula detaches the image to a temporary location (C:\) using @Command([EditDetach]).
Next, the formula adds the image file name in the img_name field.
Last, the formula shifts the focus on the document to the img_display field using @Command([EditGotoField]). Then the @Command([FileImport]) formula imports the image.
Back to top
Cleaning up the temporary location
After importing the image from its temporary location, the formula triggers an agent called Kill that deletes the image copies from the C:\ directory using the LotusScript Kill function. Create a LotusScript agent in the Notes database, call it Kill, and then copy and paste the following code into the agent's Initialize subroutine:
Back to top
Removing the image from the document
What if you add the wrong image to your document? Do you have to delete the image, file attachment, and name from all three fields? No need-just create another hotspot button and label it Clear Image. Then copy and paste the following code into the programmer's pane:
This button removes the image, attachment, and text from all fields with a single click. Now you are all set, and users will love the way your Notes document displays images as they are attached to the documents!
About the author
Ashok Hariharan is a contributor to the Lotus Developer Domain. LDD is the premier technical Web site for Lotus software products.
But no longer-you can attach and import image files in one step by:
Creating three fields on a form: a field to host the file attachment, a field to display the image, and another to display the file name.
Creating a hotspot button that attaches and displays the image file with one click.
We'll also tell you how to remove the image and file attachment from the document with one click.
Creating the form fields
Create or modify a form, adding the following fields:
Field name | Field type | Description |
img | Rich text | Hosts the image as a file attachment. |
img_display | Rich text | Displays the imported image in the document. |
img_name | Text (editable) | Displays the name of the attached file. |
Creating the hotspot button
Now create a hotspot button and label it Attach & Display. Then copy and paste the following code into the programmer's pane:
FIELD img_name := img_name; previous := @Subset(@AttachmentNames;-1); @If(@IsDocBeingEdited;"";@Command([EditDocument])); @Command([ToolsRunMacro]; "Kill"); @Command ([EditGotoField]; "img"); @If(img_name = "";@Command([EditInsertFileAttachment]);""); @If(img_name !="";@Prompt([OK];"Error"; "There is already an image attached"); @Do( @If(@Subset(@AttachmentNames;-1) = previous; ""; @Right(@Subset(@AttachmentNames;-1);3)="jpg"; @Command([EditDetach];@Subset(@AttachmentNames;-1); "c:\\image.jpg"); @Right(@Subset(@AttachmentNames;-1);3)="gif"; @Command([EditDetach]; @Subset(@AttachmentNames;-1); "c:\\image.gif");""); @SetField("img_name"; @Subset(@AttachmentNames;-1)); @Command ( [EditGotoField]; "img_display" ); @If(@Subset(@AttachmentNames;-1) = previous; @SetField("img_name";""); @Right(@Subset(@AttachmentNames;-1);3)="jpg"; @Command ( [FileImport]; "JPEG Image"; "c:\\image.jpg" ); @Right(@Subset(@AttachmentNames;-1);3)="gif"; @Command ( [FileImport]; "GIF Image"; "c:\\image.gif" ); @Subset(@AttachmentNames;-1)=""; "";@Prompt([OK];"Error";"Not a Valid Image File")))) |
Checks whether or not the document is in edit mode.
If the document is in edit mode, the formula attaches the image to the img field using @Command([EditInsertFileAttachment]).
After attaching the image, the formula detaches the image to a temporary location (C:\) using @Command([EditDetach]).
Next, the formula adds the image file name in the img_name field.
Last, the formula shifts the focus on the document to the img_display field using @Command([EditGotoField]). Then the @Command([FileImport]) formula imports the image.
Back to top
Cleaning up the temporary location
After importing the image from its temporary location, the formula triggers an agent called Kill that deletes the image copies from the C:\ directory using the LotusScript Kill function. Create a LotusScript agent in the Notes database, call it Kill, and then copy and paste the following code into the agent's Initialize subroutine:
Sub Initialize On Error Resume Next Kill "c:\image.jpg" On Error Resume Next Kill "c:\image.gif" On Error Resume Next End Sub |
Removing the image from the document
What if you add the wrong image to your document? Do you have to delete the image, file attachment, and name from all three fields? No need-just create another hotspot button and label it Clear Image. Then copy and paste the following code into the programmer's pane:
Sub Click(Source As Button) Dim workspace As New NotesUIWorkspace Dim uidoc As NotesUIDocument Set uidoc = workspace.CurrentDocument Call uidoc.FieldClear( "img" ) Call uidoc.FieldClear( "img_display") Call uidoc.FieldClear( "img_name" ) End Sub |
About the author
Ashok Hariharan is a contributor to the Lotus Developer Domain. LDD is the premier technical Web site for Lotus software products.
相关文章推荐
- POST a string and an image in one request using HttpClient
- spellchecker inspection helps locate typeos and misspelling in your code, comments and literals, and fix them in one click
- spellchecker inspection helps locate typeos and misspelling in your code, comments and literals, and fix them in one click
- 【PyCharm编辑器】之报:Spellchecker inspection helps locate typos and misspelling in your code, comments and literals, and fix them in one click.问题
- using Launch Screen Files and targetting iOS 7.1 and earlier need to also include a Launch Image in
- one command to delete all files with name "filename" in current dir and all its sub-dirs
- Applications using Launch Screen Files and targetting iOS 7.1 and earlier need to also include a Launch Image in an Asset Catalog.
- Reading and Writing CSV Files in MFC
- The development and prosperous of deep learning theory applying in computer vision(Image part)
- HowTo: ListView, Adapter, getView and different list items’ layouts in one ListView
- Count the number of alphabets, spaces, digits and other characters in one line character
- Invalid temp directory in chart handler configuration [c:\TempImageFiles\]解决方法
- Region Filling and Object Removal by Exemplar-Based Image Inpainting-code-2004
- How are the icon files in my application bundle used on iPad and iPhone
- what is the difference of select single and select up to one row in abap
- Read and Write files IN PHP
- HowTo: ListView, Adapter, getView and different list items’ layouts in one ListView
- Difference beteewn Click event and MouseClick event in .Net Winform
- Thinstall.VS v3.043 Cracked and Portable Versions in One
- how to render texture to an image in opengl——part one