Error Saving as HTML

Hello,
If you run my sample, you’ll find it won’t save the message as HTML with its related files in its folder.
This code works for many cases, but not for some!
Not sure if bug or my bad usage:

PS if you check my global GlobalHtmlFileName variable, it’s used to pass the full save path to SaveResourceHandler, not the best way, but didn’t find a better way to pass it, no other route?

WindowsApplication39.zip (3.9 MB)

@australian.dev.nerds,

The thing is that the image’s content-type doesn’t have name in your eml source.
Additional checking is needed to handle such cases. Such as the following:

instead of

ResourceFileName = Path.Combine(Path.GetFileNameWithoutExtension(GlobalHtmlFileName) + "_files", MyAttachmentBase.ContentType.Name)

try this


Dim ResourceName As String = If(String.IsNullOrEmpty(attachment.ContentType.Name),
    $"blablabla.{If(String.IsNullOrEmpty(attachment.ContentType.MediaType), String.Empty, attachment.ContentType.MediaType.Split("/"c)(1))}",
    attachment.ContentType.Name)
								 
ResourceFileName = Path.Combine(Path.GetFileNameWithoutExtension(GlobalHtmlFileName) + "_files", ResourceName)

1 Like

Hi and thanks so much for your kind help/

This is invalid char:
$"blablabla.
What’s the meaning of that part?

Also do I need to have the global var GlobalHtmlFileName?
Best :slight_smile:

@australian.dev.nerds,

It is image name without an extension. Since attachment.ContentType.Name is empty and cannot be used as a name, you can use any name you want.

Yes, you need to have a global variable.