ContentDisposition.FileName 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定電子郵件附件的建議檔案名稱。
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
屬性值
String,包含檔案名稱。
範例
下列程式代碼範例示範如何設定此屬性的值。
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();
}
備註
屬性 FileName 可讓寄件者建議用來在收件者計算機上儲存電子郵件附件的名稱。 此名稱只是建議;接收系統可以忽略它。 名稱不得包含路徑資訊;接收計算機會忽略任何這類資訊。
若要移除檔名資訊,您可以將此屬性設定為 null
或空字串 (“”) 。
Content-Disposition 標頭會在 的 https://www.ietf.orgRFC 2183 中說明。