Sdílet prostřednictvím


ContentDisposition.FileName Vlastnost

Definice

Získá nebo nastaví navrhovaný název souboru pro přílohu e-mailu.

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

Hodnota vlastnosti

A String obsahující název souboru.

Příklady

Následující příklad kódu ukazuje, jak nastavit hodnotu této vlastnosti.

public static void CreateMessageAttachment1(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, MediaTypeNames.Text.Plain);
    ContentDisposition disposition = data.ContentDisposition;
    // Suggest a file name for the attachment.
    disposition.FileName = "message" + DateTime.Now.ToString();
    message.Attachments.Add(data);
    //Send the message.
    SmtpClient client = new SmtpClient(server);
    client.Credentials = CredentialCache.DefaultNetworkCredentials;

    try
    {
        client.Send(message);
    }
    catch (Exception ex)
    {
        Console.WriteLine("Exception caught in CreateMessageAttachment1(): {0}",
            ex.ToString());
    }
    // Display the values in the ContentDisposition for the attachment.
    Console.WriteLine("Content disposition");
    Console.WriteLine(disposition.ToString());
    Console.WriteLine("File {0}", disposition.FileName);
    Console.WriteLine("Size {0}", disposition.Size);
    Console.WriteLine("Creation {0}", disposition.CreationDate);
    Console.WriteLine("Modification {0}", disposition.ModificationDate);
    Console.WriteLine("Read {0}", disposition.ReadDate);
    Console.WriteLine("Inline {0}", disposition.Inline);
    Console.WriteLine("Parameters: {0}", disposition.Parameters.Count);
    foreach (DictionaryEntry d in disposition.Parameters)
    {
        Console.WriteLine("{0} = {1}", d.Key, d.Value);
    }
    data.Dispose();
}

Poznámky

Vlastnost FileName umožňuje odesílateli navrhnout jméno, které se má použít k uložení přílohy e-mailu na počítači příjemce. Tento název je pouze návrh; přijímající systém ho může ignorovat. Název nesmí obsahovat informace o cestě; přijímající počítač tyto informace ignoruje.

Pokud chcete odebrat informace o názvu souboru, můžete tuto vlastnost nastavit na null prázdný řetězec ("").

Hlavička Content-Disposition je popsaná v dokumentu RFC 2183, který je k dispozici na adrese https://www.ietf.org.

Platí pro