Share via


ContentDisposition.FileName Proprietà

Definizione

Ottiene o imposta il nome suggerito per il file di un allegato di posta elettronica.

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

Valore della proprietà

Classe String contenente il nome del file.

Esempio

Nell'esempio di codice seguente viene illustrato come impostare il valore di questa proprietà.

static void CreateMessageAttachment1( 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,MediaTypeNames::Text::Plain );
   ContentDisposition^ disposition = data->ContentDisposition;
   
   // Suggest a file name for the attachment.
   disposition->FileName = String::Format( L"message{0}", DateTime::Now );
   message->Attachments->Add( data );
   
   //Send the message.
   SmtpClient^ client = gcnew SmtpClient( server );
   client->Credentials = CredentialCache::DefaultNetworkCredentials;
   client->Send( message );
   
   // Display the values in the ContentDisposition for the attachment.
   Console::WriteLine( L"Content disposition" );
   Console::WriteLine( disposition );
   Console::WriteLine( L"File {0}", disposition->FileName );
   Console::WriteLine( L"Size {0}", disposition->Size );
   Console::WriteLine( L"Creation {0}", disposition->CreationDate );
   Console::WriteLine( L"Modification {0}", disposition->ModificationDate );
   Console::WriteLine( L"Read {0}", disposition->ReadDate );
   Console::WriteLine( L"Inline {0}", disposition->Inline );
   Console::WriteLine( L"Parameters: {0}", disposition->Parameters->Count );
   IEnumerator^ myEnum2 = disposition->Parameters->GetEnumerator();
   while ( myEnum2->MoveNext() )
   {
      DictionaryEntry^ d = safe_cast<DictionaryEntry^>(myEnum2->Current);
      Console::WriteLine( L"{0} = {1}", d->Key, d->Value );
   }

   data->~Attachment();
   client->~SmtpClient();
}
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();
}

Commenti

La FileName proprietà consente al mittente di suggerire il nome da utilizzare per archiviare un allegato di posta elettronica nel computer del destinatario. Questo nome è solo un suggerimento; il sistema ricevente può ignorarlo. Il nome non deve includere informazioni sul percorso; tali informazioni vengono ignorate dal computer ricevente.

Per rimuovere le informazioni sul nome file, è possibile impostare questa proprietà su null o sulla stringa vuota ("").

L'intestazione Content-Disposition è descritta in RFC 2183 disponibile all'indirizzo https://www.ietf.org.

Si applica a