ContentType.Name Eigenschap

Definitie

Hiermee haalt u de waarde op van de naamparameter die is opgenomen in de header Content-Type die wordt vertegenwoordigd door dit exemplaar.

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

Waarde van eigenschap

Een String die de waarde bevat die is gekoppeld aan de naamparameter.

Voorbeelden

In het volgende codevoorbeeld wordt de waarde van de eigenschap ingesteld om een naam op te geven voor een bestand dat als stream wordt bijgevoegd.

// The following example sends a summary of a log file as the message
// and the log as an email attachment.
public static void SendNamedErrorLog(string server, string recipientList)
{
    // Create a message from logMailer@contoso.com to recipientList.
    MailMessage message = new MailMessage(
       "logMailer@contoso.com", recipientList);

    message.Subject = "Error Log report";
    string fileName = "log.txt";
    // Get the file stream for the error log.
    // Requires the System.IO namespace.
    FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
    StreamReader s = new StreamReader(fs);
    int errors = 0;
    while (s.ReadLine() != null)
    {
        // Process each line from the log file here.
        errors++;
    }
    // The email message summarizes the data found in the log.
    message.Body = String.Format("{0} errors in log as of {1}",
        errors, DateTime.Now);
    // Close the stream reader. This also closes the file.
    s.Close();
    // Re-open the file at the beginning to make the attachment.
    fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
    // Make a ContentType indicating that the log data
    // that is attached is plain text and is named.
    ContentType ct = new ContentType();
    ct.MediaType = MediaTypeNames.Text.Plain;
    ct.Name = "log" + DateTime.Now.ToString() + ".txt";
    // Create the attachment.
    Attachment data = new Attachment(fs, ct);
    // Add the attachment to the message.
    message.Attachments.Add(data);
    // 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 SendNamedErrorLog: {0}",
            ex.ToString());
    }
    data.Dispose();
    // Close the log file.
    fs.Close();
    return;
}

Opmerkingen

In het volgende voorbeeld van een Content-Type-header is "data.xyz"de waarde van de Name eigenschap.

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

Een grammatica die de syntaxis van de header Inhoudstype beschrijft, wordt beschreven in RFC 2045 Section 5.1, beschikbaar op https://www.ietf.org.

Wanneer u inhoud opgeeft voor een Attachment als een Stream of String, kunt u de Name naam instellen van het bestand waarin de inhoud op het systeem van de geadresseerde wordt opgeslagen.

Van toepassing op