attachment size causes error.

Add-in Express™ Support Service
That's what is more important than anything else

attachment size causes error.
When trying to get attachment size i get a runtime error 
martin ratcliffe




Posts: 15
Joined: 2006-08-17
The following code is called from the itemSend code.

If mail.Attachments.Count > 0 Then
MsgBox(mail.Attachments.Count.ToString)
MsgBox(mail.Attachments.Item(1).FileName)
MsgBox(mail.Attachments.Item(1).Type.ToString)
red
End If

this is just a test but the .size line give and error :-
---
Application Domain: E:\Visual Studio 2005\DocumentManagement\PAOutlookAddin\bin\Debug\
Assembly Codebase: file:///C:/WINXP/assembly/GAC_MSIL/AddinExpress.MSO.2005/2.7.1762.2005__c20c070a1fc9a144/AddinExpress.MSO.2005.dll
Assembly Full Name: AddinExpress.MSO.2005, Version=2.7.1762.2005, Culture=neutral, PublicKeyToken=c20c070a1fc9a144
Assembly Version: 2.7.1762.2005
Assembly Build Date: 10/28/2004 02:06:50

Exception Source: Microsoft.Office.Interop.Outlook
Exception Type: System.AccessViolationException
Exception Message: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Exception Target Site: get_Size

---- Stack Trace ----
Microsoft.Office.Interop.Outlook.Attachment.get_Size()
AddinExpress.MSO.2005.dll: N 00000 (0x0) JIT
PAOutlookAddin.AddinModule.adxOutlookEvents_ItemSend(sender As Object, e As ADXOlItemSendEventArgs)
AddinModule.vb: line 0153, col 13, IL 0323 (0x143)
AddinExpress.MSO.ADXOutlookAppEvents.DoItemSend(item As Object, cancel As Boolean&)
AddinExpress.MSO.2005.dll: N 0017 (0x11) IL



(Outer Exception)

Application Domain: E:\Visual Studio 2005\DocumentManagement\PAOutlookAddin\bin\Debug\
Assembly Codebase: file:///C:/WINXP/assembly/GAC_MSIL/AddinExpress.MSO.2005/2.7.1762.2005__c20c070a1fc9a144/AddinExpress.MSO.2005.dll
Assembly Full Name: AddinExpress.MSO.2005, Version=2.7.1762.2005, Culture=neutral, PublicKeyToken=c20c070a1fc9a144
Assembly Version: 2.7.1762.2005
Assembly Build Date: 10/28/2004 02:06:50

Exception Source:
Exception Type: AddinExpress.MSO.ADXExternalException
Exception Message: Error occured in the code of the add-in.
Exception Target Site: Object reference not set to an instance of an object.

---- Stack Trace ----


I would like to look through the attachment check ing the size and also the file extension to install a policy on what can be sent via outlook.

Im using outlook 2003 at the moment


Posted 17 Aug, 2006 12:12:05 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Martin.

The fact is that the Outlook.Attachment interface doesn't contain the Size property. However you can use the Extended MAPI to obtain the size of the attachment.
Posted 18 Aug, 2006 09:12:16 Top
martin ratcliffe




Posts: 15
Joined: 2006-08-17
Is there a simple way to get the total size of the email and attachmnets before send ?

I just want to limit the size of email which can be sent. I am sure i had a working example of this attachment.size though at one point but that was on a machine running outlook 2007 , i down graded outlook to check compatability. Could this be something new in outlook 2007 ?

any examples (vb) how to get the total size of an email in the itemsend call?
Posted 21 Aug, 2006 05:58:08 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Martin.

Please download the following example:
http://www.add-in-express.com/projects/oladdattachmentexample.zip
The example is written in C#. Let me know if you have any difficulties with the code and I will rewrite it in VB.NET.
Posted 21 Aug, 2006 08:14:26 Top
Alex Abramov




Posts: 3
Joined: 2006-08-24
Martin,

OL2007 does support Attachment.Size, however, older versions do not.
If you want the size of the entire email, you can simply check
mail.Size (Outlook.MailItem.Size);
Posted 24 Aug, 2006 18:13:24 Top
martin ratcliffe




Posts: 15
Joined: 2006-08-17
alex,

mail.size returns 0 when trying to call from the itemsend. Heres my code , am i doing something wrong ?

Try
mail = CType(OutlookApp.ActiveInspector.CurrentItem, Outlook.MailItem)
Catch ex As Exception
MsgBox("failed to capture mail event")
End Try

MsgBox(mail.Size())
Posted 29 Aug, 2006 04:19:58 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Alex.

Do you save the email item before you call the Size property?
Posted 29 Aug, 2006 07:28:27 Top
Alex Abramov




Posts: 34
Joined: 2006-09-15
Sergey,

Martin is the one who has the problem. And yes, I do save the event.
About your example, can you import the the MAPI class directly into the project and not define it by hand (seems like an aweful lot of work)

Alex
Posted 15 Sep, 2006 15:57:15 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Alex.

No, it is not possible. In case of the Extended MAPI, you will have to import all interfaces and constants from MSDN Library and C++ headers (*.h)in Visual Studio.
Posted 18 Sep, 2006 07:35:52 Top