ContentType.MediaType Propriedade

Definição

Obtém ou define o valor do tipo de mídia incluído no cabeçalho Content-Type representado por essa instância.

public:
 property System::String ^ MediaType { System::String ^ get(); void set(System::String ^ value); };
public string MediaType { get; set; }
member this.MediaType : string with get, set
Public Property MediaType As String

Valor da propriedade

Um String que contém o valor de tipo e subtipo de mídia. Esse valor não inclui o separador de ponto-e-vírgula (;) que segue o subtipo.

Exceções

O valor especificado para uma operação de definição é null.

O valor especificado para uma operação de definição é Empty ("").

O valor especificado para uma operação de definição em um formulário que não pode ser analisado.

Exemplos

O exemplo de código a seguir define o valor dessa propriedade.

static void CreateMessageInlineAttachment2( String^ server, String^ textMessage )
{
   
   // Create a message and set up the recipients.
   MailMessage^ message = gcnew MailMessage( L"jane@contoso.com",L"ben@contoso.com",L"A text message for you.",L"Message: " );
   
   // Attach the message string to this email message.
   Attachment^ data = gcnew Attachment( textMessage );
   
   // Send textMessage as part of the email body.
   message->Attachments->Add( data );
   ContentType^ content = data->ContentType;
   content->MediaType = MediaTypeNames::Text::Plain;
   
   //Send the message.
   // Include credentials if the server requires them.
   SmtpClient^ client = gcnew SmtpClient( server );
   client->Credentials = CredentialCache::DefaultNetworkCredentials;
   client->Send( message );
   data->~Attachment();
   client->~SmtpClient();
}
public static void CreateMessageInlineAttachment2(string server, string
textMessage)
{
    // Create a message and set up the recipients.
    MailMessage message = new MailMessage(
       "jane@contoso.com",
       "ben@contoso.com",
       "A text message for you.",
       "Message: ");

    // Attach the message string to this email message.
    Attachment data = new Attachment(textMessage);
    // Send textMessage as part of the email body.
    message.Attachments.Add(data);
    ContentType content = data.ContentType;
    content.MediaType = MediaTypeNames.Text.Plain;
    //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 CreateMessageInlineAttachment2: {0}",
            ex.ToString());
    }
    data.Dispose();
}

Comentários

No exemplo a seguir de um cabeçalho Content-Type, o valor da MediaType propriedade é "application/x-myType".

content-type: application/x-myType; name=data.xyz

Defina essa propriedade como null ou String.Empty para remover as informações de nome do cabeçalho.

A sintaxe do cabeçalho Content-Type é descrita na Seção 5.1 do RFC 2045. O RFC 2046 fornece informações detalhadas sobre tipos de mídia MIME. Esses RFCs estão disponíveis em https://www.ietf.org.

Aplica-se a