Question

I get the following exception error trying to load a file-attachment into memory when using the .load() function.

The required attribute 'Id' is missing

I cannot explicitly assign the Id property because it is readonly. Any ideas?

EmailMessage email = new EmailMessage(Exchange);
email.Attachments.AddFileAttachment("picture.jpg");
email.Attachments[0].IsInline = true;
email.Attachments[0].ContentId = "picture.jpg";
email.Attachments[0].Load(); // Errors here
Was it helpful?

Solution

The Load() method loads the attachment by making an EWS call. From your code snippet, it is bound to fail as the email object has not been created yet in Exchange, so it does not have an Id to refer to. (ref: http://msdn.microsoft.com/en-us/library/office/microsoft.exchange.webservices.data.attachment.load(v=exchg.80).aspx)

Can you give a little more background to the problem that you are trying to solve? From an above comment, you mentioned being able to Attach an email to another parent email. You might be interested to take a look at adding ItemAttachments in the link @JPRO provided above. Also refer to AttachmentCollection Class: http://msdn.microsoft.com/en-us/library/office/microsoft.exchange.webservices.data.attachmentcollection_methods(v=exchg.80).aspx

Again, as I don't know the problem you are trying to solve, these may or may not be useful to you. It would be helpful if you could give a little more context.

OTHER TIPS

Is there a reason you need to use Load? Based on this reference I believe you can attach a jpg like this:

EmailMessage email = new EmailMessage(Exchange);
byte[] picBytes = File.ReadAllBytes(@"path\to\picture.jpg");
email.Attachments.AddFileAttachment("picture.jpg", picBytes);
email.SendAndSaveCopy();

ID is set internally, is it possible the file you specified doesn't exist in the execution directory?

Have you tried loading it in as a stream instead? (http://msdn.microsoft.com/en-us/library/dd634477(v=exchg.80).aspx)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top