Hello
When going to save as html in Aspose Email, if we need to embed the resources inside output html, it’s creme de la creme, no doubt.
But the tragedy begins when we need to save the html as is, and save its resources to a folder beside it, now the most complex and non-efficient way is chosen:
In Html save options:
If EmbedResources = True Then
ASPSaveSetHTM.ResourceRenderingMode = Email.ResourceRenderingMode.EmbedIntoHtml
Else
ASPSaveSetHTM.ResourceRenderingMode = Email.ResourceRenderingMode.SaveToFile
ASPSaveSetHTM.SaveResourceHandler = AddressOf SaveHTMHandler
End If
Now, our handler:
Private Sub SaveHTMHandler(ByVal MyAttachmentBase As Email.AttachmentBase, ByRef ResourceFileName As String)
ResourceFileName = String.Empty
If Not (TypeOf MyAttachmentBase Is Email.LinkedResource) Then Return
Dim ResourcePathName As String = Path.ChangeExtension(GlobalHtmlFileName, Nothing) + "_files"
If Not Directory.Exists(ResourcePathName) Then Directory.CreateDirectory(ResourcePathName)
Select Case String.IsNullOrWhiteSpace(MyAttachmentBase.ContentType.Name)
Case False
Dim MyFileName As String = Path.GetFileName(GetNewFileTemp(ResourcePathName, MyAttachmentBase.ContentType.Name, Nothing))
ResourceFileName = Path.Combine(Path.GetFileNameWithoutExtension(GlobalHtmlFileName) + "_files", MyFileName)
MyAttachmentBase.Save(Path.Combine(ResourcePathName, MyFileName))
Case True
Dim MyFileName As String = Path.GetFileName(GetNewFileTemp(ResourcePathName, MyAttachmentBase.ContentType.MediaType.Split("/"c)(1), "." + MyAttachmentBase.ContentType.MediaType.Split("/"c)(1)))
ResourceFileName = Path.Combine(Path.GetFileNameWithoutExtension(GlobalHtmlFileName) + "_files", MyFileName)
MyAttachmentBase.Save(Path.Combine(ResourcePathName, MyFileName))
End Select
And still issues, when trying to get MyFileName from MyAttachmentBase.ContentType : Name / MediaType still a lot of conditions should be checked to prevent no value and duplicate values…
I don’t get surprised if you call it normal or say no one ever complained, but I call it… let’s say sadistic
Especially when comparing to the competitors:
Easy and safe in 3 lines of code!
Is there any logic behind such a tragic way to save html and related files and is there any hope for a simplified method like the above competitor’s method?