Convert Word DOCX Document to HTML and Embed Export Images As Base64 String | Avoid Image file cannot be written to disk Exception in C#

Hi Team,

i am facing below error while generating letter. could someone please help.

Message : Image file cannot be written to disk. When saving the document to a stream either ImagesFolder should be specified or custom streams should be provided via ImageSavingCallback. Please see documentation for details.
Source : Aspose.Words
Help link :
Data : System.Collections.ListDictionaryInternal
TargetSite : Void ()
Stack Trace : at .()
at ? .(Boolean , Byte[] , )
at ? .()
at ? .(ShapeBase , Shape , ShapeRenderer , ?? )
at ? .(ShapeBase )
at ? .(ShapeBase )
at ? .VisitShapeStart(Shape )
at Aspose.Words.Drawing.Shape.r3ka8zscesabkstb24kjjv9sml9wq7pw (DocumentVisitor )
at Aspose.Words.CompositeNode.AcceptCore(DocumentVisitor visitor)
at Aspose.Words.Drawing.Shape.Accept(DocumentVisitor visitor)
at Aspose.Words.CompositeNode.AcceptChildren(DocumentVisitor visitor)
at Aspose.Words.CompositeNode.AcceptCore(DocumentVisitor visitor)
at Aspose.Words.Paragraph.Accept(DocumentVisitor visitor)
at Aspose.Words.CompositeNode.AcceptChildren(DocumentVisitor visitor)
at Aspose.Words.CompositeNode.AcceptCore(DocumentVisitor visitor)
at Aspose.Words.Body.Accept(DocumentVisitor visitor)
at .(Node )
at .(Section )
at . ()
at .()
at .()
at ? .? ( )
at Aspose.Words.Document.(Stream , String , SaveOptions )
at Aspose.Words.Document.Save(Stream stream, SaveOptions saveOptions)
at Aspose.Words.Document.Save(Stream stream, SaveFormat saveFormat)


This Topic is created by tilal.ahmad using Email to Topic tool.

@venugopal.gogula,

You can use the following code as a workaround:

Document doc = new Document("E:\\Temp\\in.docx");

HtmlSaveOptions opts = new HtmlSaveOptions(SaveFormat.Html);
opts.ExportImagesAsBase64 = true;

MemoryStream stream = new MemoryStream();
doc.Save(stream, opts);
stream.Position = 0;