Attachment Class
Represents a mail message attachment.
- Inheritance:
- System.ObjectAttachment
Constructors
Attachment(MediaType, Byte[])
Initializes a new instance of the Attachment class with specified content type and content.
public Attachment(MediaType contentType, byte[] content)
Public Sub New(contentType As MediaType, content As Byte())
Parameters
contentType
- MediaType
The Content-Type header value.
content
- System.Byte[]
The content.
Exceptions
- System.ArgumentNullException
Content is null.
Attachment(MediaType, Stream)
Initializes a new instance of the Attachment class with specified content type and content.
public Attachment(MediaType contentType, Stream content)
Public Sub New(contentType As MediaType, content As Stream)
Parameters
contentType
- MediaType
The Content-Type header value.
content
- System.IO.Stream
The content.
Exceptions
- System.ArgumentException
Content is null or empty.
Attachment(MediaType, Stream, String)
Initializes a new instance of the Attachment class with specified content type, content and file name.
public Attachment(MediaType contentType, Stream content, string fileName)
Public Sub New(contentType As MediaType, content As Stream, fileName As String)
Parameters
contentType
- MediaType
The Content-Type header value.
content
- System.IO.Stream
The content.
fileName
- System.String
File name.
Exceptions
- System.ArgumentException
Content is null or empty.
Attachment(Stream, String)
Initializes a new instance of the Attachment class with specified content and file name.
public Attachment(Stream content, string fileName)
Public Sub New(content As Stream, fileName As String)
Parameters
content
- System.IO.Stream
The content.
fileName
- System.String
File name.
Exceptions
- System.ArgumentException
Content is null or empty.
Attachment(String)
Initializes a new instance of the Attachment class from specified file.
Parameters
filePath
- System.String
A relative or absolute path for the file.
Exceptions
- System.ArgumentException
File path is null or empty.
Properties
ContentId
Gets or sets the attachment content id.
Property Value
- System.String
The attachment content id.
Data
Gets the attachment data stream.
Property Value
- System.IO.MemoryStream
The attachment data stream.
DispositionType
Gets the attachment content disposition type.
public ContentDispositionType DispositionType { get; }
Public ReadOnly Property DispositionType As ContentDispositionType
Property Value
The attachment content disposition type.
Exceptions
- System.ArgumentException
Content disposition type cannot be set to Unknown.
FileName
Gets the file name.
Property Value
- System.String
The file name, if defined; otherwise, null.
MimeEntity
Gets the underlying MIME entity.
public ContentEntity MimeEntity { get; }
Public ReadOnly Property MimeEntity As ContentEntity
Property Value
The underlying MIME entity.
Size
Gets the data size.
Property Value
- System.Nullable<System.Int32>
The data size, if defined; otherwise, null.
Methods
GetTaggedProperty(PropertyTag)
Returns the value stored into a specific tagged property. Works only for messages loaded from MSG files.
public object GetTaggedProperty(PropertyTag tag)
Public Function GetTaggedProperty(tag As PropertyTag) As Object
Parameters
tag
- PropertyTag
The ID of the tag from which to retrieve the value.
Returns
- System.Object
An System.Object containing the value of the specified tag or null if the property was not found.
Save(Stream)
Saves the attachment into the specified stream.
Parameters
stream
- System.IO.Stream
The stream in which to save the attachment.
Save(String)
Saves the attachment into the specified path.
Parameters
path
- System.String
The path to which to save the attachment.
SetTaggedProperty(PropertyTag, Object)
Explicitly sets the value of a tagged property. Works only for messages that will be saved to a MSG file. Items set with this method will be written when saving the message to .msg, overwriting any other properties normally set by other members, which can cause errors.
For example, setting GemBox.Email.Msg.Properties.PropertyTag.AttachDataBinary will override the attachment's binary content regardless of what is on Data.
public void SetTaggedProperty(PropertyTag tag, object value)
Public Sub SetTaggedProperty(tag As PropertyTag, value As Object)
Parameters
tag
- PropertyTag
The ID of the tag to set.
value
- System.Object
The value of the tagged property.