ContentDisposition 类

定义

表示 MIME 协议 Content-Disposition 标头。

public class ContentDisposition
继承
ContentDisposition

示例

下面的代码示例创建一封电子邮件,其中包含要以内联方式显示的附件。

public static void CreateMessageInlineAttachment(string server, string
textMessage)
{
    // Create a message and set up the recipients.
    MailMessage message = new MailMessage(
       "jane@contoso.com",
       "ben@contoso.com",
       "An inline text message for you.",
       "Message: ");

    // Attach the message string to this email message.
    Attachment data = new Attachment(textMessage, MediaTypeNames.Text.Plain);
    // Send textMessage as part of the email body.
    message.Attachments.Add(data);
    ContentDisposition disposition = data.ContentDisposition;
    disposition.Inline = true;
    //Send the message.
    // Include credentials if the server requires them.
    SmtpClient client = new SmtpClient(server);
    client.Credentials = CredentialCache.DefaultNetworkCredentials;

    try
    {
        client.Send(message);
    }
    catch (Exception ex)
    {
        Console.WriteLine("Exception caught in CreateMessageInlineAttachment: {0}",
            ex.ToString());
    }
    data.Dispose();
}

注解

类中 ContentDisposition 的信息在将电子邮件发送到目标时附带包含附件的电子邮件。 中 ContentDisposition 的信息可由显示电子邮件的软件使用,以发件人预期的方式显示电子邮件附件。

Email消息是使用 类的MailMessage实例创建的。 类的 Attachment 实例用于向电子邮件添加附件。 若要修改 ContentDisposition 附件的 ,请从 Attachment.ContentDisposition 属性获取 实例。

要作为消息正文的一部分显示的内容的处置类型为 Inline。 未显示但附加在单独文件中的内容的处置类型 Attachment为 。 Inline使用 属性控制与 实例关联的附件的ContentDisposition处置类型。

对于文件附件,可以使用 的属性 ContentDisposition 来设置文件大小,以及文件的创建日期、上次读取日期和上次修改日期。 对于所有附件,如果附件存储在接收计算机上,则可以设置建议的文件名。

方法 ToString 返回 Content-Disposition 标头。 在 上提供的 https://www.ietf.orgRFC 2183 中介绍了 Content-Disposition 标头。

构造函数

ContentDisposition()

AttachmentDispositionType 初始化 ContentDisposition 类的新实例。

ContentDisposition(String)

使用指定的处置信息初始化 ContentDisposition 类的新实例。

属性

CreationDate

获取或设置文件附件的创建日期。

DispositionType

获取或设置电子邮件附件的处置类型。

FileName

获取或设置电子邮件附件的建议文件名称。

Inline

获取或设置 Boolean 值,该值确定电子邮件附件的处置类型(内联或附件)。

ModificationDate

获取或设置文件附件的修改日期。

Parameters

获取由此实例表示的 Content-Disposition 标头中包括的参数。

ReadDate

获取或设置文件附件的读取日期。

Size

获取或设置文件附件的大小。

方法

Equals(Object)

确定指定 ContentDisposition 对象的 Content-Disposition 标头是否等于此对象的 Content-Disposition 标头。

GetHashCode()

确定指定 ContentDisposition 对象的哈希代码。

GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回此实例的 String 表示形式。

适用于

产品 版本
.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