We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Saving attachment from msg using string as index instead of integer ; error please help


I was trying to save an attachement from my msg file but im getting an error. i thought it is posible since other controls can do that aswel. the error is:
" Conversion from string “List.xls” to type ‘Integer’ is not valid."

and the code that im trying to execute is:
Dim msg As MapiMessage = MapiMessage.FromFile(D:\test.msg)
dim index as string = “List.xls”
msg.Attachments.Item(index).Save(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & “\Downloads” & index)


Thank you for your inquiry.

It seems that you are using an older version of Aspose.Email for .NET component, because I couldn’t find Item member in Aspose.Email.Outlook.MapiAttachmentCollection class. Please check the below source code with Aspose.Email for .NET v1.3.0.

Dim message = Aspose.Email.Outlook.MapiMessage.FromFile(“C:\temp\message.msg”)
Dim attachments = message.Attachments
attachments(0).Save(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + attachments(0).LongFileName)


instead of Attchment(0).save(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + attachments(0).LongFileName)

can we replace 0 with the name of the attachment? that is what im trying to accomplish, so idont have to loop to all the attchment to get the file name.


Attachment(“Filename”).Save(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + attachments(“Filename”).LongFileName)


Thank you for your feedback.

I do not think you can pass a string (attachment name) instead of an integer index value. MapiMessage.Attachments is a collection of type MapiAttachment and you can access the indexed value by passing the integer only.