Spostare un WEB attachment in un Rich Text Field

TIPS DEVELOPERS

  • 3 commenti
IL File Upload Control si occupa di inserire gli attachment da WEB, ma dopo che tale funzionalità viene eseguita, l'allagato viene posizionato in basso alla FORM in cui viene utilizzato.

Per fare in modo che l'allegato venga posizionato in un campo rich-text specifico bisogna lavorare sulla WebQuerySave della FORM ecco come:

*********************************
Sub Initialize
  Dim s As New notesSession
  Dim doc As notesDocument
  Set doc = s.documentContext
  Call WebMoveAttachment(Doc, "")
End Sub
*********************************


La subroutine "WebMoveAttachment" si occupa di spostare l'attachment nel rich-text FIELD.

*********************************
Function WebMoveAttachment(doc As notesDocument, Byval moveToFieldName As String)
  ' This function moves a file attached via the Web with the File Upload Control to a rich text field.
  Dim s As New notesSession
  Dim tempDir As String
  Dim v2FileNames As Variant
  Dim i As Integer
  Dim attachedFile As notesEmbeddedObject
  Dim filePath As String
  Dim rtItem As notesRichTextItem
 
  tempDir = s.getEnvironmentString("Directory", True)
  ' Put a trailing slash at the end of the directory if it is needed
  If Instr(tempDir, "/") <> 0 And Right(tempDir, 1) <> "/" Then tempDir = tempDir & "/"
  If Instr(tempDir, "\") <> 0 And Right(tempDir, 1) <> "\" Then tempDir = tempDir & "\"
  ' Get the names of all the attachments (1 or more)
  v2FileNames = Evaluate("@AttachmentNames", doc)
  For i = Lbound(v2FileNames) To Ubound(v2FileNames)
     If v2FileNames(i) <> "" Then   ' Make sure it's a valid file name
        Set attachedFile = doc.getAttachment(v2FileNames(i))
        filePath = tempDir & v2FileNames(i)
        ' Save the file on the server
        Call attachedFile.extractFile(filePath)
        ' Create the rich text item and re-attach the file
        If doc.hasItem(moveToFieldName) Then
           Set rtItem = doc.getFirstItem(moveToFieldName)
           ' Add a couple of lines to the rich text field before re-attaching the file
           Call rtItem.addNewLine(2)
        Else
           Set rtItem = New notesRichTextItem(doc, moveToFieldName)
        End If
        Call rtItem.embedObject(1454, "", filePath)
        ' Delete the file(s) from the server file system
        Kill filePath
     End If
  Next   ' Move on to the next file name
End Function
*********************************

3 Commenti:

  • #1 Daniele 06/30/2005 11:15:25 AM

    In pratica si dimentica di cancellare l'attachment...

    Quindi devi mettere questa istruzione prima dell'ultimo If.

    call attachedFile.Remove che praticamente elimina l'item dell'attachment temporaneo...

    Tutto chiaro?

  • #2 Daniele 06/30/2005 11:06:22 AM

    Cosa succede esattamente sia sulla console che sul DOC?

  • #3 sba 06/30/2005 10:45:55 AM

    vengono sdoppiati gli allegati.

    ho anche provato ad aggiungere la remove del object ma nisba.

    idee ???

Commenta articolo
 

Questo spazio web è stato creato da per un uso pubblico e gratuito. Qualsiasi tipo di collaborazione sarà ben accetta.
Per maggiori informazioni, scrivete a info@dominopoint.it

About Dominopoint
Social
Dominopoint social presence: