ContentDisposition::FileName Property

 

Gets or sets the suggested file name for an e-mail attachment.

Namespace:   System.Net.Mime
Assembly:  System (in System.dll)

public:
property String^ FileName {
	String^ get();
	void set(String^ value);
}

Property Value

Type: System::String^

A String that contains the file name.

The FileName property allows the sender to suggest the name to be used to store an e-mail attachment on the recipient's computer. This name is a suggestion only; the receiving system can ignore it. The name must not include path information; any such information is ignored by the receiving computer.

To remove file name information, you can set this property to null or the empty string ("").

The Content-Disposition header is described in RFC 2183 available at http://www.ietf.org.

The following code example demonstrates how to set the value of this property.

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 e-mail 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();
}


.NET Framework
Available since 2.0
Return to top
Show: