Condividi tramite


ContentType.Parameters Proprietà

Definizione

Ottiene il dizionario che contiene i parametri inclusi nell'intestazione Content-Type rappresentata da questa istanza.

public:
 property System::Collections::Specialized::StringDictionary ^ Parameters { System::Collections::Specialized::StringDictionary ^ get(); };
public System.Collections.Specialized.StringDictionary Parameters { get; }
member this.Parameters : System.Collections.Specialized.StringDictionary
Public ReadOnly Property Parameters As StringDictionary

Valore della proprietà

Oggetto scrivibile StringDictionary che contiene coppie nome e valore.

Esempio

Nell'esempio di codice seguente vengono visualizzati i valori nel dizionario restituito da questa proprietà.

public static void CreateMessageWithMultipleViews(string server, string recipients)
{
    // Create a message and set up the recipients.
    MailMessage message = new MailMessage(
        "jane@contoso.com",
        recipients,
        "This email message has multiple views.",
        "This is some plain text.");

    // Construct the alternate body as HTML.
    string body = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">";
    body += "<HTML><HEAD><META http-equiv=Content-Type content=\"text/html; charset=iso-8859-1\">";
    body += "</HEAD><BODY><DIV><FONT face=Arial color=#ff0000 size=2>this is some HTML text";
    body += "</FONT></DIV></BODY></HTML>";

    ContentType mimeType = new System.Net.Mime.ContentType("text/html");
    // Add the alternate body to the message.

    AlternateView alternate = AlternateView.CreateAlternateViewFromString(body, mimeType);
    message.AlternateViews.Add(alternate);

    // Send the message.
    SmtpClient client = new SmtpClient(server);
    client.Credentials = CredentialCache.DefaultNetworkCredentials;

    try
    {
        client.Send(message);
    }
    catch (Exception ex)
    {
        Console.WriteLine("Exception caught in CreateMessageWithMultipleViews(): {0}",
            ex.ToString());
    }
    // Display the values in the ContentType for the attachment.
    ContentType c = alternate.ContentType;
    Console.WriteLine("Content type");
    Console.WriteLine(c.ToString());
    Console.WriteLine("Boundary {0}", c.Boundary);
    Console.WriteLine("CharSet {0}", c.CharSet);
    Console.WriteLine("MediaType {0}", c.MediaType);
    Console.WriteLine("Name {0}", c.Name);
    Console.WriteLine("Parameters: {0}", c.Parameters.Count);
    foreach (DictionaryEntry d in c.Parameters)
    {
        Console.WriteLine("{0} = {1}", d.Key, d.Value);
    }
    Console.WriteLine();
    alternate.Dispose();
}

Commenti

È possibile impostare i parametri specificando l'intero valore Content-Header durante la costruzione di un ContentType oggetto oppure è possibile aggiungere parametri all'oggetto StringDictionary restituito dalla Parameters proprietà .

Quando si aggiunge una voce di parametro al dizionario, il nome del parametro è la chiave della voce e il valore del parametro è il valore della voce.

Una grammatica che descrive in dettaglio la sintassi dell'intestazione Content-Type è descritta in RFC 2045 Sezione 5.1. RFC 2046 fornisce informazioni dettagliate sui tipi di supporti MIME e sui relativi parametri associati. Queste RFC sono disponibili all'indirizzo https://www.ietf.org.

Si applica a