AttachmentCollection attachmentCollection in C #

I am trying to use the AttachmentCollection class in C #, and when I try to create a new instance of it, it gives me the error message "Error 32 Type" System.Net.Mail.AttachmentCollection "has no specific constructors" .... That's what I tried How to create a new instance of this if no constructors are defined?

AttachmentCollection attachmentCollection = new AttachmentCollection();

Thank you for your help!

+3
source share
4 answers

Some types are not intended to be instantiated.

They can be abstract, which means you must extend the class and fill in some of its functions.

, . , .

, " AttachmentCollection MailMessage.AlternateViews MailMessage.Attachments". , , ; MailMessage.

MailMessage AttachmentCollections . MailMessage, AlternateViews Attachments, , .

, , . , .

+5

, .

MailMessage "message = new MailMessage (...)" ( AttachmentCollection) "message.Attatchments.Add(...)", .

AttachmentCollection , , MailMessage.

msdn AttachmentCollection.

+4

, AttachmentCollection. MSDN ( messages.Attachments.add(foo):

string file = "data.xls";
MailMessage message = new MailMessage(
   "jane@contoso.com",
   "ben@contoso.com",
   "Quarterly data report.",
   "See the attached spreadsheet.");

Attachment data = new Attachment(file, MediaTypeNames.Application.Octet);
// Add time stamp information for the file.
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);
// Add the file attachment to this e-mail message.
message.Attachments.Add(data);
+3

, , :

AttachmentCollection attachmentCollection = new MailMessage().Attachments;
0

Source: https://habr.com/ru/post/1715436/


All Articles