OutlookAttachment Class
Definition
- Assembly
- Bodu.Formats.Outlook.Msg.dll
- Package
- Bodu.Formats.Outlook.Msg 0.7.1
- Source
- OutlookAttachment.cs
Represents one attachment of an OutlookMessage: a typed view over the attachment storage's decoded properties, with access to the by-value payload or the nested attached message.
public sealed class OutlookAttachment
- Inheritance
-
OutlookAttachment
- Inherited Members
- Extension Methods
Remarks
The conveniences return null when the underlying property is absent; every attachment property remains reachable through Properties. Content access is method-specific: OpenContentStream() serves a by-value payload and OpenMessage() serves an embedded message - each throws NotSupportedException for every other method kind.
Properties
ContentId
Gets the content identifier used to reference the attachment from an HTML body.
public string? ContentId { get; }
Property Value
FileName
Gets the attachment file name, preferring the long form.
public string? FileName { get; }
Property Value
Method
Gets how the attachment's content is stored.
public OutlookAttachmentMethod Method { get; }
Property Value
- OutlookAttachmentMethod
The
PidTagAttachMethodvalue when present and defined. When the property is absent, an attachment that carries a by-value content stream reports ByValue (real-world writers frequently omit the method); otherwise None.
MimeTag
Gets the attachment MIME type.
public string? MimeTag { get; }
Property Value
Properties
Gets every decoded property of the attachment.
public MapiPropertyCollection Properties { get; }
Property Value
- MapiPropertyCollection
The tag-addressed property collection.
Remarks
A by-value payload (PidTagAttachDataBinary) larger than
MaxInlineAttachmentBytes is not decoded: the property is present with
a null value and the content is served by OpenContentStream() directly from the
container.
Size
Gets the attachment size.
public long? Size { get; }
Property Value
- long?
The
PidTagAttachSizevalue the writer recorded; when absent, the length of the by-value content stream; null when neither is available.
Remarks
The stream length comes from the container directory, so a deferred payload is never read to measure it.
Methods
OpenContentStream()
Opens the by-value content payload as a read-only stream.
public Stream OpenContentStream()
Returns
- Stream
The content stream; dispose it when reading is complete.
Remarks
A payload decoded inline (at or below MaxInlineAttachmentBytes) is served from the decoded bytes without copying. A larger payload is opened from the container: under Streaming it is read sector by sector on demand, and a container fault during a read surfaces as OutlookMsgFormatException.
Exceptions
- ObjectDisposedException
The owning session has been disposed.
- NotSupportedException
The attachment's Method is not ByValue - a referenced, embedded, or OLE attachment carries no byte payload in the message.
- OutlookMsgFormatException
The by-value content stream is missing, or the container is malformed.
OpenMessage()
Opens the nested attached message.
public OutlookMessage OpenMessage()
Returns
- OutlookMessage
The nested message session. It shares the root session's container and named-property mapping; disposing it is a no-op, and it becomes unusable when the root session is disposed.
Exceptions
- ObjectDisposedException
The owning session has been disposed.
- NotSupportedException
The attachment's Method is not EmbeddedMessage.
- OutlookMsgFormatException
The embedded-message storage is missing or malformed, or the nested message would sit deeper than MaxEmbeddedMessageDepth.
ToString()
Returns a textual form of the attachment for diagnostics.
public override string ToString()
Returns
- string
The method and file name.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |