Manage Learn to apply best practices and optimize your operations.

Check attachment size before doc is saved

This tip describes how to check attachment sized before doc is saved.

Use the following code in the Querysave event to prevent saving a document that exceeds size limits you want to impose.

To avoid getting an extra prompt to save the document when the limit is exceeded, you'll either want to use the formula "@If(@Command([FileSave]);@Command([FileCloseWindow])" or use a hidden, editable "SaveOptions" field on the form, with a default text value of "1". If you use the SaveOptions field, then enable the "fieldsettext" calls in the script below.
 

Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument
Dim totalSize As Long

Set uidoc = ws.CurrentDocument
Set doc = uidoc.document

Call uidoc.refresh(True)
Dim rtitem As Variant
Dim embedObjs As Variant

Set rtitem = doc.getFirstItem("Body")
embedObjs = rttem.embeddedObjects
totalSize = 0
dim oneMB as long
oneMB = 1048576


If Not Isempty(embedObjs) Then
 For i = 0 To Ubound(embedObjs)
  totalSize = totalSize + embedObjs(i).
filesize
  If embedObjs(i).filesize > 2 * oneMB 
Then
     Msgbox("Your attachment '"  +
embedObjs(i).name +"' is " +Cstr(Round
     (embedObjs(i).filesize / oneMB,1)) +"    
mb. The limit is 2.0 mb.")
     continue = False
     'Call uidoc.fieldsettext
("SaveOptions","0")
   End If
 Next

 If totalSize > 4 * oneMB Then
    Msgbox("Your total attachment size is " 
+Cstr(Round (totalSize /
    oneMB,1)) +" mb.  The limit is 4.0 mb.")
    continue = False
    'Call uidoc.fieldsettext("SaveOptions","0")
  End If
End If

Dig Deeper on LotusScript

SearchWindowsServer

Search400

  • Favorite iSeries cheat sheets

    Here you'll find a collection of valuable cheat sheets gathered from across the iSeries/Search400.com community. These cheat ...

  • HTML cheat sheet

    This is a really cool cheat sheet if you're looking to learn more about HTML. You'll find just about everything you every wanted ...

  • Carol Woodbury: Security

    Carol Woodbury

SearchDataCenter

SearchContentManagement

Close