Attachment.ContentStream is not working properly

Hello


I have a little problem with the attachment.ContentStream

I’ve tested it with a .txt-File.

The content of the txt-File is for example "Hello World"

and when i read the attachment.ContentStream with a StreamReader, it shows me “HelloWorldHello World” so it doubles the content. Maybe i’m doing something wrong.

I’m using the latest version of aspose.email

Here is the code that I use

greetz drew

foreach (Attachment attachment in message.Attachments)
{
attachmentName[counter] = attachment.Name;
contentType[counter] = attachment.ContentType.ToString();
stream[counter] = attachment.ContentStream;
attachment.Save(stream[counter]);
counter++;
}
return stream;

Hi,

Thank you for your inquiry.

I think the problem is due to the reason that you are overwriting the indexed stream with same contents. Below is source code for your reference. Please give it a try with latest version of Aspose.Email for .NET v1.3.0 and let us know of your results.

C#

var message = Aspose.Email.Mail.MailMessage.Load(“C:\temp\message.msg”);
int counter = 0;
string[] attachmentName = new string[message.Attachments.Count];
string[] contentType = new string[message.Attachments.Count];
Stream[] stream = new Stream[message.Attachments.Count];
foreach (Attachment attachment in message.Attachments)
{
attachmentName[counter] = attachment.Name;
contentType[counter] = attachment.ContentType.ToString();
stream[counter] = attachment.ContentStream;
[//attachment.Save ](https://attachment.save/)(stream[counter]);
counter++;
}

Thank you!


This worked for me! :slight_smile:

greetz drew