Domino Code Fragment

Code Name*
Prevent large attachments
Date*
09/13/2002
Source (or email address if you prefer)*
k1blankenship@charter.net
IP address:.24.98.18.133
Description*
Since I couldn't prevent a person from attaching a large file before the document is saved,
I ended up putting this code into the PostSave event. I say, let the person save the doc,
then interrogate the data, and if the file is too large, oh well, see ya..... I give them
a message. I found that I have to close the UI instead of allowing users to stay in edit
mode, as there's some residual pointer left over. Sometimes the pointer or image
shows up as if there is an attachment, but errs out when you click on it. This also takes
into account multiple attachments, and removes only the ones that are over the limit.
Enjoy, Keith Blankenship
Type*
LotusScript
Categories*
OLE/ActiveX Integration, User Interface (Notes)
Implementation:
Modify code
Required Client:
(none)
Server:
(none)
Limitations:
IF some yoyo loads up a really big attachment, it'll get saved, only to have it deleted. If they do it enough it could fragment the database, not to speak of slowing things down.
Comments:
Hope this helps.
PS. you'll have to the messagebox statement back together?
Files/Graphics attachments (if applicable): Code:
Dim doc As NotesDocument
Dim rtitem As Variant
Dim DollarFile As Variant
Set Doc = Source.Document
Set rtitem = Doc.GetFirstItem( "docattachment" )
Set DollarFile = Doc.GetFirstItem( "$File" )
If ( rtitem.Type = RICHTEXT ) Then
If Not(DollarFile Is Nothing) Then
Forall o In rtitem.EmbeddedObjects
If ( o.Type = EMBED_ATTACHMENT ) Then
If o.FileSize > 512000 Then
tFileSize$ = Cstr((o.FileSize/1024))
Messagebox "You are attaching a file that is " & tFileSize$
&" kilobytes. We regret that you may not attach a file over 500 kilobytes
in size. This document will be saved as requested, however the attachment
will be removed. Thank you."
Call o.Remove
Doc.docattachments = ""
Call Doc.Save(True, False)
Call Source.close
End If
End If
End Forall
End If
End If