How to dynamically attach file in a notes document?

Dear All

I am facing a problem related to file attachment.

I have create an html form through my agent in which I used a element of type file, which basically browse the file.

Now user selects the file and click on the OK button a notes document is creating with a notes richtext item. this is done by an agent. my code is given below

Dim rtfEmbeddedObj As NotesEmbeddedObject

Dim rtfAttachFile As NotesRichTextItem

If strChkMultiplePC=“Yes” Then

Set rtfAttachFile = New NotesRichTextItem (docRequest,“fldAttach”)

Set rtfEmbeddedObj =rtfAttachFile.EmbedObject(EMBED_ATTACHMENT, “”,filePath$)

End If

but it gives error that file not found, even the file exists.

field “fldAttach” does not exists in the document, I want to create it dynamically, even the entier document is creating dynamically. What could be the problem. Please help me.

Is it possible to create a “RichText” type field at run time?

is it necessary that “fldAttach” must be exists before attachment.

if this code is wrong then let me suggest the correct syntax.

Please help me, it’s urgent

Regards

Ashish

Subject: How to dynamically attach file in a notes document?

Hmm - code looks ok at first glance. Are you sure that filePath$ is getting populated correctly? Can you check it in debugger?

HTH

Kiers

Subject: How to dynamically attach file in a notes document?

Wait a moment.

Your agent prints out HTML that contains a file upload control?

The form action (?) of the HTML form calls an agent that tries to read the file from a path on the the machine where that agent runs (which is the server)?

If I got you right, this is never going to work. Maybe you could describe in more detail what your business goal and requirements are.

Subject: RE: How to dynamically attach file in a notes document?

as per our requirement I am writing code in agent to generate a html form, which have some fields. all the fields and their label name are defined in the master document, agent collects all fields and its corresponding label and generate form. there is one field, where user can attach .csv , .xls or .txt file. for this I write a syntax .

Now when I click on “save” button, this will first validate the required condition and creates a notes document.

on click of save button I write another agent which create a notes document with all the fields in the form. Now in save agent, I have written following code to make attachment in the notes document

If strChkMultiplePC=“Yes” Then

Set rtfAttachFile = New NotesRichTextItem (docRequest,“fldAttach”)

set rtfEmbeddedObj = rtfAttachFile.EmbedObject(EMBED_ATTACHMENT, “”,strAttachFile)

End If

When I debug this code it does not throw any error and attachment is created perfectly. but when it is in release mode. It show the error file not found.

even I tried with hardcoded file name which exists in my C drive.

It shows the error.

This is the problem. Please help me.

Regards

Ashish

Subject: RE: How to dynamically attach file in a notes document?

By “debug mode” and “release mode”, I assume you mean “testing locally using Preview” and “testing on the server”. Please note that LotusScript running on the server (the only place it CAN run in a web application) cannot access files on your local machine – the file must exist on the server. When you test locally, the file does exist on the “server”, since the server is your local machine.

Subject: RE: How to dynamically attach file in a notes document?

Thank you very very much sir.

I tried your suggested approach, and it works. Thank you once again.

let suppose the user, who is creating a document and who does not have access on the server, and he wants to attach file, which is in local machine. then what we’ll do? is it possible to make a copy of that file on the server first and then attach?

another how to extraxt the attached file and save it locally, because right now when I click on the file it opens in the web browser.

please suggest me the approach or any sample code

thanks

regards

Ashish

Subject: RE: How to dynamically attach file in a notes document?

Use a Domino file upload control (Create->Embedded Element->Field Upload Control). Note that browser security will NOT allow you to force a user to attach any file, but you may check the path and filename of any file the user selects.

Subject: RE: How to dynamically attach file in a notes document?

Sorry, but I don’t have UIInterface(i.e. Notes Form). My UI interface is generated by an agent. then is it possible to use of Domino File Upload control? I don’t have any idea about this.

Regards

Ashish

Subject: RE: How to dynamically attach file in a notes document?

Any particular reason WHY you are not using a form? Please note: Domino restricts file uploads for security reasons; Domino-generated upload controls include the CD record offset in the name attribute to indicate that the application designer intended the control to exist.

Subject: RE: How to dynamically attach file in a notes document?

Hello Sir,

thanks for your quick response.

Actually, this is the client requirement. all the fields, their label, position and style every thing is defined in the master document. User selects their division~company~location and the language, based on this a I get all the fields and label for the selected division~company~location for the selected language and place it into a HTML form in a defined position.

For this I wrote my code in an agent.

and that’s why I suppose it is not possible to take a notes form. I don’t know because I am new in this technology.

I appreciate, if you can suggest me.

Thanks

Regards

Ashish

Subject: RE: How to dynamically attach file in a notes document?

If plain everything has to be set up in configuration documents, this is not going to be too easy. The best approach would probably be to create a Notes form through DXL (Domino’s XML format) then. Sounds to me like it should be possible using XSLT. But honestly, I haven’t done anything comparable yet.

Forget about the other approach, though. You might just be able to retrieve the bytes for the file attachment from the Request_Content field. Again, I’ve never tried that. But, you’d have to extract them, write to a file on the server and re-import them all in your own code. What’s even worse: Since you are on 6.5, the Request_Content field is limited to 64 kiB of data.