Aspose.words : converting word to html

Hi Team,

I have requirement to convert word(include images) to HTML and saving it in SharePoint document library.

Product: Aspose.words for .NET (latest version will be using)

Can you please share the sample code for it.

Regards,
Vimalraj V

@Vimal89v,

You can use the following simple code to convert Word into HTML with embedded images inside. After that you save this single HTML in SharePoint’s document library:

Document doc = new Document("E:\\temp\\in.docx");
HtmlSaveOptions opts = new HtmlSaveOptions(SaveFormat.Html);
opts.PrettyFormat = true;
opts.ExportImagesAsBase64 = true;
doc.Save("E:\\temp\\19.2.html", opts); 

P.S. We would also suggest you please go through the following blog post and video tutorial:
Using Aspose.Total for .NET with SharePoint for File Creation and Manipulation

HI Hafeez,

Thanks for input.

Here i need one additional information with respect to my requirement.

I am setting opts.ExportImagesAsBase64 = false; so images will be saved. Here i can save the images only to local, but i am not able to save the images to SharePoint document library.

Since we have set path value in HTMLoptions.Imagefolder , it is accepting local folder, if i set SharePoint library path it is throwing file not found error.

Please guide me how to handle this.

sample path set as below:

htmloptions.ImagesFolder = "http://xxx/sites/xxxx/Destination";

Regards,
Vimalraj V

@Vimal89v,

Aspose.Words for SharePoint supports converting Word documents to HTML format (with embedded images inside). In this case the HTML file will be stored inside the Document Library.

Please tell, are you getting this problem with “Aspose.Words for SharePoint” or Aspose.Words for .NET API?

I’m getting problem with [Aspose.Words for .NET] version: 19.2.0.0 with C#

below is sample code:

using (var htmlstream = new MemoryStream())
{
    HtmlSaveOptions options4lib = new HtmlSaveOptions(SaveFormat.Html);

    options4lib.ExportImagesAsBase64 = false;

    string url = site.Url + "/" + destlib + "/" + file.Name;
    var fileName = list.RootFolder.Files.GetByUrl(url);
    Uri uri = new Uri(url);
    string filename = uri.LocalPath;

    options4lib.ImagesFolder = filename;

    Document doc1 = new Document(fileStream);
    doc1.Save(htmlstream, options4lib);
}

@Vimal89v,

Aspose.Words for .NET can save images to local disk during saving Word document to HTML. You then have to push those files to your SharePoint’s Document Library. Of-course, you do not need Aspose.Words for .NET to push files to SharePoint’s Document Library. Instead, Microsoft provides an API for that in Microsoft.SharePoint namespace.

You can use SPFolder.Files.Add() to add a file. An example here: https://docs.microsoft.com/en-us/previous-versions/office/sharepoint-server/ms412207(v=office.15) might be helpful.