In my application, there are some attachments (rich text lite) fields, where the users can attach a lot of docs, with pop up window as they asked to be.
But now, I need a validation in these fields. The only type of attachment permited is .pdf. Any onther type of document must be prohibited.
I have no idea how I can do this, and I’m not good using Lotusscript language.
You could put some code in the Onchange event for the Rich Text Lite field. That could would look in the field, detect any attachment and warn teh user (or even delete the attachment) if the extension is incorrect.
What I would do, however, is to use the OpenFileDialog method of the NotesUIWorkspace class. There you can filter so only PDF files are being displayed. It won’t stop a user from changing the filter and selecting another type of file, but you can check the return value and ignore any files without the .pdf extension.
This method will also not prevent the user form manually attaching a file in the field. You can make that harder by not displaying the field delimiters on the rich text field.
In teh long run, there is only so much you can do, if users keep attaching the wrong type of files by bypassing the restrictions you have setup, it is a management issue, and their managers need to stop it.
I followed you advice and made a script to open a dialogbox for select the file to attach on onChange event. But the problem is…
My script only gets his file and returns the full path. I don’t know how I can get this file and put its on RTF and check if its a .pdf file or not, with my code.
Dim session As New NotesSession
Dim ws As New NotesUIWorkspace
Dim dataDir As String
Dim files As Variant
Dim windowTitle As String
Dim filters As String
dataDir = session.GetEnvironmentString("Directory", True)
files = ws.OpenFileDialog(False, windowTitle, filters, dataDir)
If Isempty(files) Then
GetSingleFileName = ""
Elseif Not Isarray(files) Then
GetSingleFileName = Cstr(files)
Else
GetSingleFileName = files(Lbound(files))
End If
You could check the extension, using Left$.It would not be 100% safe, as the user could use a different extension, but in most cases it would work fine.
I use a simple class I wrote a while back to parse file names, I posted it on my blog for you to look at: http://planetlotus.org/a89774
The formatting of the code get ruined here in this forum, so I prefer to post code on my blog.
I just posted an expanded class of file functions, it also contain methods to copy and move files (one at a time or whole directories), create and delete directories, etc.