Quantcast
Channel: Open XML Format SDK forum
Viewing all articles
Browse latest Browse all 1288

Replace HTML into Word docx Adds BOM to File

$
0
0
I am inserting html text into a docx word document. All works okay except the end result docx file has a BOM at the beginning of the document.xml. I do not understand this although I suspect an encoding issue. Example code below. Would appreciate anyone's thoughts on this.

        void AddAltChunkHTML(MainDocumentPart mainPart, Word.SdtElement sdt, SPFile filename)
        {
            string altChunkId = "AltChunkId" + id;
            id++;
            // read insert data
            byte[] byteArray = filename.OpenBinary();

            AlternativeFormatImportPart chunk = mainPart.AddAlternativeFormatImportPart(AlternativeFormatImportPartType.Xhtml, altChunkId);

            // load the insert data into the chunk
            using (MemoryStream mem = new MemoryStream())
            {
                mem.Write(byteArray, 0, (int)byteArray.Length);
                mem.Seek(0, SeekOrigin.Begin);
                chunk.FeedData(mem);
            }

            Word.AltChunk altChunk = new Word.AltChunk();
            altChunk.Id = altChunkId;
            //Replace content control with altChunk information

            OpenXmlElement parent = sdt.Parent;
            parent.InsertAfter(altChunk, sdt);
            sdt.Remove();
        }

Viewing all articles
Browse latest Browse all 1288