Aspose Email tragic Html save algorithm, serious reconsideration needed

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 :smiley:

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? :slight_smile:

It seems like you’re frustrated with the complexity of the method provided by Aspose. While I can’t directly address Aspose Email’s development decisions, I can certainly discuss some reasons for the approach.

  • Flexibility and customization. The approach taken by Aspose Email allows for control over how resources are handled and saved. By providing various conditions and options, developers can customize the process according to their specific requirements.
  • Error handling. The our approach handle different scenarios related to content types and file extensions. While this might seem complex, it could also be an attempt to provide better error handling and prevent unexpected issues. The use of detailed conditions might be intended to prevent ambiguity and conflicts when generating file names for resources. This can be crucial to ensure that there are no naming collisions or unintended behavior.
  • Competing priorities. Sometimes, the developer might prioritize certain features or performance optimizations over user convenience. While a simpler method might be appealing, it might also lack some of the customization options that the current approach provides.

We have an extensive library and try to cover as many possibilities as possible. What is sadistic for you is flexibility for others. We cannot meet the convenience requirements of all users at the same time.
You can use the library that is most convenient for you.
In other hand, if you’re seeking a more concise solution, you could encapsulate the complexity in a utility class or function within your own codebase, abstracting away some of the intricacies for easier use.

1 Like

Hello and thanks, sure you’re not invloved in that, just posted this to open a ticket for developers to see and consider, in development, for each task there are many algorithms and paths to go, and I just mentioned that not a good way for this task is chosen, show me where’s the flexibility and customization and I’ll show you a very much more simplified way, for this task.
Anyway, still appreciate if a ticket opened, even if not implemented :slight_smile:

@australian.dev.nerds,

I’m afraid I can’t see any point in continuing this discussion.

I’m sorry that our API doesn’t meet your requirements for convenience.

Thanks for your insights.