Free Support Forum - aspose.com

How to save the word doc to html format with the images from URL address(not local machine)

Hi, I am new in Aspose.word component. I tried to save a word document into Html format, and the document contains some images which come from server side(I am going to put this web application on server) therefore, the address of export image folder has to be URL format.

I know how to use doc.saveoption.HtmlExportImagesFolder, but it only works for local folder. Is there any way I can specify the folder as URL address? Does HtmlExportImagesFolderAlias use on this situation? If yes, could you please provide some example code?
Here is my code:
Dim FilePath As String = “C:\XXXX.docx”
Dim doc As New Aspose.Words.Document(FilePath)
Dim stream As Stream = New MemoryStream()
Dim path As String = Request.Url.AbsoluteUri
path = path.Replace(Request.Url.AbsolutePath, “”)
doc.SaveOptions.HtmlExportImagesFolder = path + “/Temp/”
doc.Save(stream, SaveFormat.Html)
Dim pos = stream.Position
stream.Position = 0
Dim reader As New StreamReader(stream)
Dim str = reader.ReadToEnd()
txtDesc.Text = Server.HtmlDecode(str)
stream.Close()


Thanks for your help.

Hi Jiachu,


Thanks for your inquiry.

Sure, you can use HtmlSaveOptions.ImagesFolderAlias property to Specifies the name of the folder used to construct image URIs written into an HTML document.

When you save a Document in HTML format, Aspose.Words needs to save all images embedded in the document as standalone files. ImagesFolder property allows you to specify where the images will be saved and ImagesFolderAlias allows to specify how the image URIs will be constructed.

  1. If ImagesFolderAlias is not an empty string, then the image URI written to HTML will be ImagesFolderAlias + .
  2. If ImagesFolderAlias is an empty string, then the image URI written to HTML will be ImagesFolder + .
  3. If ImagesFolderAlias is set to ‘.’ (dot), then the image file name will be written to HTML without path regardless of other options.

Here is the sample code:

Dim doc As New Document(“Rendering.doc”)

' This is the directory we want the exported images to be saved to.

Dim imagesDir As String = Path.Combine("Images")

' The folder specified needs to exist and should be empty.

If Directory.Exists(imagesDir) Then

Directory.Delete(imagesDir, True)

End If

Directory.CreateDirectory(imagesDir)

' Set an option to specify specify alias of the folder. in our case this is part of url

Dim options As New HtmlSaveOptions(SaveFormat.Html)

options.ImagesFolder = imagesDir

options.ImagesFolderAlias = "http://localhost/test/"

doc.Save(MyDir & "Document.SaveWithOptions Out.html", options)


I hope, this helps.

Best regards,

Thanks for your help, I had better understanding of using HtmlExportImagesFolderAlias method.

My next question is if I can make the image export folder on server side? My website try to save the document(by Aspose.word) after user finished their editing by using a rich textbox controller. However, I need to put the document on server side with HTML format, but I don’t know how to cope with the images if they are only saved on local computer.
1 Like

Hi Jiachu,


Thanks for your inquiry. As mentioned in my previous reply, please use HtmlSaveOptions.ImagesFolder property to export images to a separate folder on server.

When you save a Document in HTML format, Aspose.Words needs to save all images embedded in the document as standalone files. ImagesFolder allows you to specify where the images will be saved and ImagesFolderAlias allows to specify how the image URIs will be constructed. If you save a document into a file and provide a file name, Aspose.Words, by default, saves the images in the same folder where the document file is saved. Use ImagesFolder to override this behavior.
Please let me know if I can be of any further assistance.

Best regards,