Adding an attachment by button

An user came up to me with a problem of adding an attachment to a form by using a button on the form (this db is a notes based db). When pressing the button, a pop-up window displays asking for what type of file the user is opening and the file itself. The problem is that when the user selects a file that is in 5 folders (Ex: D:\My Documents\Customer Opportunities\Customer Files\ASC Fed Opps\ASC FALCON\ASC Falcon Discovery kits COST and Services Summary 10-24-06.xls), she will receive the error “File not found”.

I tried to solve this problem in several ways:

  1. I asked her to reduce the name of the file and she continued to receive the error.

  2. I asked her to take out the file of all folders and put it on her desktop and try to add the attachment. She did not receive the error and was able to add the attachment.

  3. She tried a different file that was in the same folders as the example and did not receive any errors.

The code for the “Add Attachment” button is below. Any help would be appreciated.

Dim ws As New NotesUIWorkspace

Dim ns As New NotesSession

Dim SourceDoc As NotesUIDocument

Dim db As NotesDatabase

Dim thisDoc As NotesDocument

Dim attdoc As NotesDocument

Dim flag As Integer,pos As Integer

Dim rtItem As NotesRichTextItem

Dim multfiles As Variant,temp As String ',filename As String

Dim secureArray(1) As String

Dim view As NotesView

Set SourceDoc=ws.CurrentDocument

secureArray(0)=“NotesAdmin”

secureArray(1)=“[SOW]”

flag = ws.DialogBox( “attachmentPopup” , True, True , True, True, False, False, “Add Attachment”, False, True )

If flag Then

Set db=ns.CurrentDatabase

Call SourceDoc.FieldSetText (“AttFileName”,ns.GetEnvironmentString(“AttFileName”))

Call SourceDoc.Refresh

Set thisDoc=SourceDoc.document

multFiles=thisDoc.AttFileName

Forall filename In multFiles

  Set attdoc=db.CreateDocument

  attdoc.Form="Attachment"

  pos=0

  For i=Len( filename) To 1 Step -1

     temp=Mid(filename,i,1)

     If temp="\" Then

pos=i

Exit For

     End If

  Next

pos=Len(filename)-pos

attdoc.attname=Right$( filename,pos)

attdoc.Description= SourceDoc.FieldGetText(“Description”)

attdoc.AttType= SourceDoc.FieldGetText(“AttType”)

attdoc.ATTACH_CREATED = Today

If isSecured(attdoc.AttType(0)) Then

  attdoc.readers=secureArray

  attdoc.GetFirstItem("readers").IsReaders=True

End If

Set rtItem=attdoc.CreateRichTextItem(“attachment”)

Call rtItem.EmbedObject ( EMBED_ATTACHMENT, “”,filename)

Call attdoc.MakeResponse(thisDoc)

Call attdoc.Save(True,True)

End Forall

Call SourceDoc.FieldSetText(“AttFileName”,“”)

Call SourceDoc.FieldSetText(“Description”,“”)

Call SourceDoc.FieldSetText(“AttType”,“”)

Call SourceDoc.Refresh

Set view=db.GetView(“attachments”)

Call view.refresh

Call ws.viewRefresh

End If

Subject: Adding an attachment by button

Why not use Formula? See => http://www-10.lotus.com/ldd/nd6forum.nsf/DateAllThreadedweb/57adfb2f85384d398525726400513780?OpenDocument

Subject: RE: Adding an attachment by button

This code was already in the form and I did not really want to modify anything to the code unless it’s really necessary. When the user adds an attachment, it shows up in an emedded view on the bottom of the form. So the code you showed me in formula language would not solve the problem. Is the problem that the file is in too many folders? Is there a limit of how many characters?

Subject: RE: Adding an attachment by button

Without testing, one thing I wonder is if the string isn’t perhaps growing too long. Possibly instead than having it too many folders deep, this could be an issue. I recommend testing this by creating a test directory structure with the same number of folder levels, but with short file names. VB strings have a limit of 255 characters, but it can’t hurt to test it using a simple structure.

Subject: RE: Adding an attachment by button

Joel, I did thought about the possibility of the file being in too many folders. I suggested to her (the user) to take out the file and put it on her desk top and she was able to add the attachment. My question is why was she not able to attach that specific file but when she selected another file that was in 5 folders, she was able to add the attachment with no errors? This is what puzzles me the most. Is it possible that the file itself was corrupted? I asked her to send me the file but she told me that she deleted it since she doesn’t use it anymore. Any other ideas would be appreciated.

Subject: Solved the problem

I was able to solve the problem. In the 2nd folder, there was something wrong with the directory structure that made the folder corrupted. I created a new folder and copied the contents from the corrupted folder and pasted them into the new folder. The user was able to add the attachment with no errors. Does anyone know how to diagnose the specific problem with the corrupted folder?

Subject: Another possiblity

My husband, Zevi, suggested the possibility of it being a permissions issue. If you are logged onto the user’s computer using administrator access, right click on the folder and select properties. Under the Security Tab there is an “advanced” button. Press this button and check the Effective Permissions tab. Subfolders can also inherit permissions from the parent folder. This is an option that can be checked here.

-Yonit David