Table of Contents

Constructor Attachment

Namespace
LMKit.Data
Assembly
LM-Kit.NET.dll

Attachment(string)

Initializes a new instance of the Attachment class by loading the content from the specified file path. The file must be one of the supported formats:

  • PNG
  • BMP
  • GIF
  • PSD
  • PIC
  • JPEG
  • PNM
  • HDR
  • TGA
  • WEBP
  • TIFF
  • HTML
  • TXT
  • PDF
  • DOCX
  • XLSX
  • PPTX
public Attachment(string path)

Parameters

path string

The file system path to the attachment file.

Examples

using LMKit.Data;
using System;

// Load a PDF document
var pdfAttachment = new Attachment("report.pdf");
Console.WriteLine($"Loaded: {pdfAttachment.Name}, {pdfAttachment.Length} bytes");

// Load an image
var imageAttachment = new Attachment("photo.jpg");
Console.WriteLine($"Is image: {imageAttachment.IsImage()}");

// Load a Word document
var docAttachment = new Attachment("document.docx");
Console.WriteLine($"Is document: {docAttachment.IsDocument}");

Exceptions

FileNotFoundException

Thrown when the specified file does not exist.

UnsupportedFileTypeException

Thrown when the file format is not supported (see above for supported formats).

See Also

Attachment(byte[], string)

Initializes a new instance of the Attachment class with the provided data and name. The data must represent one of the supported formats:

  • PNG
  • BMP
  • GIF
  • PSD
  • PIC
  • JPEG
  • PNM
  • HDR
  • TGA
  • WEBP
  • TIFF
  • HTML
  • TXT
  • PDF
  • DOCX
  • XLSX
  • PPTX
public Attachment(byte[] data, string name)

Parameters

data byte[]

The byte array representing the content of the attachment.

name string

The name of the attachment file.

Exceptions

ArgumentNullException

Thrown when data or name is null.

UnsupportedFileTypeException

Thrown when the file format is not supported (see above for supported formats).

Attachment(Stream, string)

Initializes a new instance of the Attachment class by reading the content from the provided stream and using the given file name. The stream must contain data representing one of the supported formats:

  • PNG
  • BMP
  • GIF
  • PSD
  • PIC
  • JPEG
  • PNM
  • HDR
  • TGA
  • WEBP
  • TIFF
  • HTML
  • TXT
  • PDF
  • DOCX
  • XLSX
  • PPTX
public Attachment(Stream data, string name)

Parameters

data Stream

A readable Stream containing the attachment data. The stream is fully read; it is not disposed by the constructor.

name string

The logical file name associated with this attachment.

Exceptions

ArgumentNullException

Thrown when data or name is null.

ArgumentException

Thrown when data is not readable.

UnsupportedFileTypeException

Thrown if the stream data is not one of the supported formats.

See Also

Attachment(ImageBuffer, bool, string)

Initializes a new Attachment from an in-memory image buffer.

public Attachment(ImageBuffer image, bool ownsImage = true, string name = "image")

Parameters

image ImageBuffer

The image buffer containing pixel data. Cannot be null.

ownsImage bool

Whether this instance takes ownership of image and will dispose it when disposed. Default: true.

name string

The logical name for this attachment. Default: "image".

Remarks

This constructor performs no I/O operations and therefore does not require an asynchronous variant.

Exceptions

ArgumentNullException

Thrown if image is null.

Attachment(Uri, AttachmentDownloadingProgressCallback)

Initializes a new instance of the Attachment class by loading content from the specified URI.

public Attachment(Uri uri, Attachment.AttachmentDownloadingProgressCallback downloadingProgress = null)

Parameters

uri Uri

The URI to load the attachment from. Supports file:// for local files and http:// or https:// for remote resources.

downloadingProgress Attachment.AttachmentDownloadingProgressCallback

An optional callback to report download progress for remote URIs. The callback receives the total content length (if known) and bytes read so far. Return false to cancel the download.

Remarks

For remote URIs, this constructor blocks while downloading. Consider using CreateFromUriAsync(Uri, AttachmentDownloadingProgressCallback, CancellationToken) for non-blocking downloads in UI applications.

Exceptions

ArgumentNullException

Thrown when uri is null.

FileNotFoundException

Thrown when a local file URI points to a non-existent file.

UnsupportedFileTypeException

Thrown when the downloaded content is not a supported format.

HttpRequestException

Thrown when the remote resource cannot be downloaded.

OperationCanceledException

Thrown when the download is canceled via the progress callback.

See Also