Outlook MailItem Attachments

  • Thread starter Thread starter Peter Wullems
  • Start date Start date
P

Peter Wullems

I am trying to convert some code from VB to C# where VB.NET allows the
following:
MailItem.Attachments.Add(filename)
In the same situation C# appears to look for the following:
MailItem.Attachments.Add(object Source, object Type, object Position, object
DisplayName);
What should I supply to the parameters?

thanks

Peter
 
Peter,

The reason for this is that when importing COM signatures, optional
parameters are not allowed. Because of this, you have to pass a special
value to the other parameters, that value being
System.Reflection.Missing.Value. Pass that to the other parameters, and it
should be fine.

Hope this helps.
 
The difference is that C# doesn't support default parameters

you need to call it as:

MailItem.Attachments.Add(fileName, Type.Missing, Type.Missing, Type.Missing);

Regards

Richard Blewett - DevelopMentor

http://staff.develop.com/richardb/weblog

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<[email protected]>

I am trying to convert some code from VB to C# where VB.NET allows the
following:
MailItem.Attachments.Add(filename)
In the same situation C# appears to look for the following:
MailItem.Attachments.Add(object Source, object Type, object Position, object
DisplayName);
What should I supply to the parameters?

thanks

Peter



---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.760 / Virus Database: 509 - Release Date: 10/09/2004



[microsoft.public.dotnet.languages.csharp]
 
If you have problems after this, you may also want to box
Type.Missing.Value as an object before doing it too, depending on your
version of Outlook.

I've run into problems where interop worked in Office 2003, but I had to
box it beforehand to get it to work in Office 2000. Word is also a bit
more picky than the other apps.
 
Thanks. All now makes sense.

cheers

Peter
Nicholas Paldino said:
Peter,

The reason for this is that when importing COM signatures, optional
parameters are not allowed. Because of this, you have to pass a special
value to the other parameters, that value being
System.Reflection.Missing.Value. Pass that to the other parameters, and
it should be fine.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Peter Wullems said:
I am trying to convert some code from VB to C# where VB.NET allows the
following:
MailItem.Attachments.Add(filename)
In the same situation C# appears to look for the following:
MailItem.Attachments.Add(object Source, object Type, object Position,
object DisplayName);
What should I supply to the parameters?

thanks

Peter
 
Back
Top