3.17 Attachment

Describes an attachment to a Message object.

3.17.1 Properties

The following table lists properties along with their access and descriptions.

Property

Access

Description

Application

R/O

Application. The Application object.

AttachmentSize

R/O

Long. The size of the attachment (in bytes).

ContentId

R/O

String. The MIME Content-ID of the attachment.

ContentType

R/O

String. The MIME Content-Type of the attachment.

DisplayName

R/O

String. The descriptive name to be displayed to users.

FileName

R/O

String. The name of the file this attachment represents.

Hidden

R/O

Boolean. Whether or not the GroupWise client has hidden the attachment.

Message

R/O

Message. The Message object that this attachment represents.

ModifiedDate

R/O

Date. The date and time this attachment was last modified.

ObjType

R/O

Enum (AttachmentTypeConstants). The type of this attachment.

Parent

R/O

Attachments collection. The Attachments collection that owns this object.

Stream

R/O

Returns a GWStream object, which is used to retrieve data from large attachments. In the GWStream object, you can specify how many bytes of the attachment to read and also position the point in the attachment data to start reading. This functionality allows you to read the attachment data in several different data blocks. For an example of how to use this property, see the Example section below.

3.17.2 Methods

Delete()

Deletes the attachment from the associated attachments collection and the associated message. This method functions on draft or personal items only.

Save(String Filename)

Saves this attachment to the file specified by Filename. Not supported if ObjType is egwMessage.

3.17.3 Remarks

If ObjType is egwMessage, the Message property points to the attached message and the Filename property is ignored (it should be an empty string ("")). If ObjType is not egwMessage, the Filename property is the file name for the attached file, movie file, multimedia file, embedded OLE object, or linkedOLE object info. In this case, the Message property is ignored (it should be "Nothing").

An Attachment object is refreshed when its parent object is refreshed. When an Attachment object is refreshed, it recursively refreshes its Message object

3.17.4 Example

In GWStream, you can specify how many bytes of the attachment to read. You can also specify the starting point within the attachment data from which to start reading to read the attachment in chunked data blocks. The following example shows how to read data and write it to a file:

Private Sub btnSave_Click(ByVal sender As Object, 
   ByVal e As System.EventArgs) Handles btnSave.Click

     Dim stream As GroupwareTypeLibrary.GWStream
     Dim arr() As Byte
     Dim str As String
     Dim fs As System.IO.FileStream
     Dim bw As System.IO.BinaryWriter

     On Error GoTo -1
     str = txtDirectory.Text + "\" + txtName.Text
     fs = New System.IO.FileStream
        (str, IO.FileMode.Create, IO.FileAccess.Write)
     bw = New System.IO.BinaryWriter(fs)

     stream = gwAttachment.stream
     arr = stream.Read(512)
     While arr.Length <> 0
          bw.Write(arr)
          If arr.Length <> 512 Then Exit While
          arr = stream.Read(512)
     End While
     fs.Close()
End Sub

The Seek() method specifies the position from which to start reading the data. By default, the position in the data is automatically updated when you read, so you don't need to call the Seek() method to read, unless you want to start reading from a different position. When a GWStream object is first retrieved, the read position is at the beginning of the data. You can call Seek() to reread data by moving the read position back to the beginning of the data.

The Write() method is only used to write data in a Stream object that can be passed in as the attachment data for the Attachments.AddEx()method.