none
AltChunks gives corrupted document. RRS feed

  • Question

  • Hi,

    My Company generates a very large amount of Word documents that are assembled via OpenXML from data in a database. Some of the content is database fields which contains RTF text, which we add as AltChunks. This is very standard use of OpenXML, and it has been running along nicely for months. Recently, however, we discovered that some of the generated documents fail to open in Word.

    When we try to open one of the bad documents, Word will complain and ask if we want to fix it, if we agree to that, Word fixes the document, but the content of the AltChunk is gone.

    The issue is a bit of a headscratcher for us, because;

    • Some of the documents with RTF AltChunks open just fine,
    • All documents open fine with Word 2010 v.14.0.4760, but with Word 2010 v.14.0.6023, they won't.

    So, it appears as if there's some RTF that Word doesn't like, not all, and that the dislike was introduced in a patch or update recently. Has anyone else experienced this issue?

    Tuesday, April 15, 2014 9:42 AM

Answers

  • Follow-up;

    The fileblock on RTF setting in Word was the culprit. Re-enable reading RTF in Word, and it all Works as it should.

    /Torben

    • Marked as answer by Torben Poder Wednesday, April 30, 2014 8:32 AM
    Wednesday, April 30, 2014 8:32 AM

All replies

  • Hi Torben,

    Welcome to post in MSDN forums.

    Could you please share the code that inserts the RTF text into the Word document as altChunks element with us? Have you tried to open the file in other version of Word application? How about Word 2013? I think firstly you need to figure out if it's a problem with the update or patch of the Office application, by trying opening the file in different version of Word. If it doesn't work only with Word 2010 v.14.0.6023, then you could submit a feedback in User Voice.

    If it doesn't work in various of versions of Word application, then we need your code to reproduce this problem and find out if it's a problem with your code.

    These links might give you some help:

    how to write RTF to docx file

    Converting RTF to HTML

    How to Use altChunk for Document Assembly


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, April 16, 2014 8:44 AM
    Moderator
  • Hi Torben

    Can you provide a sample of the RTF that doesn't work? Preferably as a file you use as an AltChunk - if you could post it on OneDrive or something similar?


    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, April 16, 2014 1:43 PM
    Moderator
  • Hi, thank you for the speedy replies :)

    The code is a bit difficult to isolate, but the actual insertion is this;

    var s = @"{\rtf1\ansi\deff0 {\fonttbl {\f0 Times New Roman;}}\f0\fs24 {\pard This is the tekst in the paragraph! \par}}";//
    var altChunkID = string.Format("dasId{0}{1}", notat.LoebeNr, tekst.SekvensNummer);
    AlternativeFormatImportPart chunk = doc.MainDocumentPart.AddAlternativeFormatImportPart(AlternativeFormatImportPartType.Rtf, altChunkID);
    using (MemoryStream ms = new MemoryStream(Encoding.ASCII.GetBytes(s))) {
        chunk.FeedData(ms);
        AltChunk altChunk = new AltChunk {
                                        Id = altChunkID
                                    };
    
        docPart.Body.Append(altChunk);    
    }

    In this case I've just created 's' as a dummy test. Unfortunately, I cannot share neither the generated docx, nor the RTF content, as it is confidential data.

    Regards.

    Torben Poder



    Wednesday, April 23, 2014 10:48 AM
  • Hi Torben

    And you can repro the problem with the code snippet you've provided?

    I notice that the start and end tags of the paragraph don't match in what you've provided:

     {\pard This is the tekst in the paragraph! \par}}";//

    pard vs par

    Is this correct (should this work)?


    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, April 23, 2014 4:47 PM
    Moderator
  • Hi Cindy,

    Yes that code will cause Word to hiccup.

    The actual RTF doesn't seem to matter, the code has literally run through millions of different pieces of RTF, more or less well-formed, and it would seem the issue is not in the RTF content, but in the fact that the content is RTF.

    I stated in my original post that some docs will open with RTF chunks in them, but that turns out to be a mistake on my part; no RTF chunks will open.

    We're leaning heavily into suspecting the recent batch of patches regarding RTF security, which will explain why it used to work and now doesn't, but still works on the server, since the server version haven't gotten those Word patches yet.

    /Torben

    Friday, April 25, 2014 8:12 AM
  • Follow-up;

    The fileblock on RTF setting in Word was the culprit. Re-enable reading RTF in Word, and it all Works as it should.

    /Torben

    • Marked as answer by Torben Poder Wednesday, April 30, 2014 8:32 AM
    Wednesday, April 30, 2014 8:32 AM
  • Thank you for sharing that with us. Was this something specific to a patch, as you mentioned in a previous message, or another setting in Word? (And now that you say this, I can imagine which one...)

    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, April 30, 2014 4:01 PM
    Moderator
  • Going from memory.. Options -> Trust Center -> Settings -> FileBlock  ..something like that

    Obviously, turning off a security setting is never a good idea, but sometimes you really must..

    /Torben

    Thursday, May 1, 2014 8:25 PM