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

Free Support Forum - groupdocs.com

PNG conversion overwrites existing files for certain emails in .NET

Converting certain emails with the following code leads to a System.IO.IOException, because the code tries to overwrite already existing files.
This happens because GroupDocs conversion passes “1” as page number twice when requesting the page stream. As only one page should be rendered, there shouldn’t even be a 2nd call, but a second call with the same page number is even more strange.

using (var conv = new Converter(documentPath))
{
	var imgOptions = new ImageConvertOptions()
	{
		Format = Conv.FileTypes.ImageFileType.Png,
		//convert only the first page for thumbnail
		PageNumber = 1,
		PagesCount = 1,
		Width = 256
	};

	SavePageStream getPageStream = page => new FileStream(string.Format("output{0}.png", page), FileMode.CreateNew);
	conv.Convert(getPageStream, imgOptions);
}

Looks like this behavior is new in GroupDocs 21.10 or 21.11.
It only happens with some emails, I’ve attached two for testing:
sample emails.zip (215.0 KB)

1 Like

@Clemens_Pestuka

We are looking into this scenario. Your investigation ticket ID is CONVERSIONNET-4998.

1 Like

@Clemens_Pestuka

There’s some issue with the code you shared because if email has attachments, they are also converted to PNG. You can also convert email and each attachment based on the file type to different format.
Please try the following approach and let us know:

using (var conv = new Converter(documentPath))
{
    var imgOptions = new ImageConvertOptions()
    {
        Format = GroupDocs.Conversion.FileTypes.ImageFileType.Png,
        //convert only the first page for thumbnail
        PageNumber = 1,
        PagesCount = 1,
        Width = 256
    };
    var counter =  1;
    SavePageStream getPageStream = page => new FileStream($"output-{counter++}-{page}.png", FileMode.CreateNew);
    conv.Convert(getPageStream, imgOptions);
}
1 Like

Hi @Atir_Tahir,

I’m sorry for the late reply.
Unfortunately I skipped some part of the code for simplifying the sample.
We are actually using EmailLoadOptions with “ConvertOwned” set to false.

I understand that attachments are converted in my sample, but with the missing “ConvertOwned” flag set to false, this should no longer be the case.
But this flag is somehow ignored now and the attachment is converted as well, leading to the described error. This has changed with a recent version change (I think 21.10 or 21.11)

1 Like

@Clemens_Pestuka

We are further looking into this scenario.

1 Like