Share via


ContentType.ToString Método

Definição

Retorna uma representação de cadeia de caracteres desse objeto ContentType.

public:
 override System::String ^ ToString();
public override string ToString ();
override this.ToString : unit -> string
Public Overrides Function ToString () As String

Retornos

Um String que contém as configurações atuais para este ContentType.

Exemplos

O exemplo de código a seguir exibe a representação de cadeia de caracteres de um ContentType.

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

O valor do ToString método contém a cadeia de caracteres usada para criar este ContentType, se um tiver sido especificado e nenhum valor de propriedade tiver sido alterado. Se nenhuma cadeia de caracteres tiver sido especificada ou se um ou mais valores de propriedade tiverem sido alterados desde que isso ContentType foi criado, o valor de será uma cadeia de ToString caracteres no formato de um cabeçalho Content-Type composto usando os valores de propriedade atuais. A cadeia de caracteres não inclui o "Content-type:" prefixo .

A sintaxe do cabeçalho Content-Type é descrita na Seção 5.1 do RFC 2045, disponível em https://www.ietf.org.

Aplica-se a