2 Şubat 2018 Cuma

Attachment Sınıfı

Giriş
Şu satırı dahil ederiz.
using System.Net.Mail;
Kullanım
Nesne MailMessage nesnesine eklenir
Attachment attachment = ...;
mail.Attachments.Add (attachment);
Constructor - Stream + Name
Şöyle yaparız.
MemoryStream memoryStream = ...;
string fileName = ...;
mail.Attachments.Add(new Attachment(memoryStream, fileName));
Constructor - Stream + Name + MediaType
Stream'den şöyle kurarız.
byte[] data = ... ;
MemoryStream ms = new MemoryStream(data);
mail.Attachments.Add( new Attachment( ms, "example.txt", "text/plain" ));
Constructor - String
Dosyadan şöyle kurarız.
string file = ...;
Attachment attc = new Attachment(file);
Constructor - String + MediaType
Dosyadan şöyle kurarız.
string file = "data.xls";
Attachment data = new Attachment(file, MediaTypeNames.Application.Octet);

ContentDisposition disposition = data.ContentDisposition;
disposition.CreationDate = System.IO.File.GetCreationTime(file);
disposition.ModificationDate = System.IO.File.GetLastWriteTime(file);
disposition.ReadDate = System.IO.File.GetLastAccessTime(file);
ContentId Alanı
Şöyle yaparız.
attachment.ContentId = contentId;
TransferEncoding Alanı
Şöyle yaparız.
attachment.TransferEncoding = TransferEncoding.Base64;

Hiç yorum yok:

Yorum Gönder