Attachment.CreateAttachmentFromString Method

Definition

Creates an attachment from a string.

Overloads

CreateAttachmentFromString(String, ContentType)

Creates a mail attachment using the content from the specified string, and the specified ContentType.

CreateAttachmentFromString(String, String)

Creates a mail attachment using the content from the specified string, and the specified MIME content type name.

CreateAttachmentFromString(String, String, Encoding, String)

Creates a mail attachment using the content from the specified string, the specified MIME content type name, character encoding, and MIME header information for the attachment.

CreateAttachmentFromString(String, ContentType)

Source:
Attachment.cs
Source:
Attachment.cs
Source:
Attachment.cs

Creates a mail attachment using the content from the specified string, and the specified ContentType.

public static System.Net.Mail.Attachment CreateAttachmentFromString (string content, System.Net.Mime.ContentType contentType);

Parameters

content
String

A String that contains the content for this attachment.

contentType
ContentType

A ContentType object that represents the Multipurpose Internet Mail Exchange (MIME) protocol Content-Type header to be used.

Returns

An object of type Attachment.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

CreateAttachmentFromString(String, String)

Source:
Attachment.cs
Source:
Attachment.cs
Source:
Attachment.cs

Creates a mail attachment using the content from the specified string, and the specified MIME content type name.

public static System.Net.Mail.Attachment CreateAttachmentFromString (string content, string? name);
public static System.Net.Mail.Attachment CreateAttachmentFromString (string content, string name);

Parameters

content
String

A String that contains the content for this attachment.

name
String

The MIME content type name value in the content type associated with this attachment.

Returns

An object of type Attachment.

Remarks

If the content is in ASCII format then the character encoding is set to ASCII. For all other formats, the character encoding is set to utf-8. The default media type is plain text.

If the content is not in ASCII format and the encoding is null, utf-8 encoding is used.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

CreateAttachmentFromString(String, String, Encoding, String)

Source:
Attachment.cs
Source:
Attachment.cs
Source:
Attachment.cs

Creates a mail attachment using the content from the specified string, the specified MIME content type name, character encoding, and MIME header information for the attachment.

public static System.Net.Mail.Attachment CreateAttachmentFromString (string content, string? name, System.Text.Encoding? contentEncoding, string? mediaType);
public static System.Net.Mail.Attachment CreateAttachmentFromString (string content, string name, System.Text.Encoding contentEncoding, string mediaType);

Parameters

content
String

A String that contains the content for this attachment.

name
String

The MIME content type name value in the content type associated with this attachment.

contentEncoding
Encoding

An Encoding. This value can be null.

mediaType
String

A String that contains the MIME Content-Header information for this attachment. This value can be null.

Returns

An object of type Attachment.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1