Problem with SaveFileDialog

This script resides on an action button in the inbox. It loops through all selected docs in the inbox and gives the file save prompt box. It defaults in the subject line as the file name, and if multiple selections it will remember last saved directory for the next. The files are saved as .ndl format.

The script works fine up to two selections, but not more than that. I’ve narrowed the problem to using the email subject as the filename - if I use a default of say “test.ndl” it works fine. I thought of invalid characters in the subject, but the results are the same no matter which two emails are first.

Any ideas?

Thanks,

William

Sub Click(Source As Button)

Dim ws As New NotesUIWorkspace

Dim uiview As NotesUIView

Dim session As New NotesSession

Dim db As NotesDatabase

Dim repid_db$

Set db = session.CurrentDatabase

repid_db$ = Left$(db.ReplicaID, 8) + “:” + Right$(db.ReplicaID, 8) ’ format dbase replica id

’ use all docs view for .ndl retrieval

Dim alldocs As NotesView

Dim unid_alldocs$

Set alldocs = db.GetView(“($All)”)

’ format unid for all docs view

unid_alldocs$ = “OF” + Left$(alldocs.UniversalID, 8) + “:” + Mid$(alldocs.UniversalID, 9, 8)_

  • “-ON” + Mid$(alldocs.UniversalID, 17, 8) + “:” + Right$(alldocs.UniversalID, 8)

Dim dc As NotesDocumentCollection

Dim doc As NotesDocument

Set uiview = ws.CurrentView

Set dc = uiview.Documents

Set doc = dc.GetFirstDocument

Dim unid_doc$

Dim dirname$

dirname$ = "c:" ’ default directory

Dim docsubject$

Dim docfile$

While Not (doc Is Nothing) ’ loop thru all selected docs

docsubject$ = doc.Subject(0) ’ get doc subject

docfile$ = Trim$(docsubject$ + “.ndl”) ’ use doc subject for default file name

’ format unid of doc

unid_doc$ = “OF” + Left$(doc.UniversalID, 8) + “:” + Mid$(doc.UniversalID, 9, 8)_

  • “-ON” + Mid$(doc.UniversalID, 17, 8) + “:” + Right$(doc.UniversalID, 8)

’ open save dialog

filenames = ws.SaveFileDialog( False,"Save - " + docsubject$, dirname$, docfile$)

If Not(Isempty(filenames)) Then

If Dir$(filenames(0)) = “” Then ’ check if file already exists

’ if no then create doc link

fileNum% = Freefile()

Open filenames(0) For Output As fileNum%

Print #fileNum%, “”

Print #fileNum%, "<REPLICA " + repid_db$ + “>”

Print #fileNum%, "<VIEW " + unid_alldocs$ + “>”

Print #fileNum%, "<NOTE " + unid_doc$ + “>”

Print #fileNum%, “”

Close fileNum%

Else

’ if yes then ask to overwrite

Dim answer%

answer% = Messagebox(“File exists! Overwrite?”, 4+32, “Overwrite?”)

If answer% = 6 Then

fileNum% = Freefile()

Open filenames(0) For Output As fileNum%

Print #fileNum%, “”

Print #fileNum%, "<REPLICA " + repid_db$ + “>”

Print #fileNum%, "<VIEW " + unid_alldocs$ + “>”

Print #fileNum%, "<NOTE " + unid_doc$ + “>”

Print #fileNum%, “”

Close fileNum%

End If

End If

dirname$ = Strleftback(filenames(0), "", 0, 1) ’ get directory for next file save

End If

Set doc = dc.GetNextDocument (doc)

Wend

End Sub

Subject: Problem with SaveFileDialog

Actually, the problem is invalid characters for a file name. It didn’t like the colon after the Re. Need to check for all invalid characters - /:*?"<>|