Issue converting from RTF to docx and doc. RRS feed

  • Question

  • Hi

    I am converting the RTF file to docx and doc by using SaveAs.

    But for some files we are getting COM Exception :

    System.Runtime.InteropServices.COMException (0x800A1554): A file error has occurred.
       at Microsoft.Office.Interop.Word.DocumentClass.SaveAs(Object& FileName, Object& FileFormat, Object& LockComments, Object& Password, Object& AddToRecentFiles, Object& WritePassword, Object& ReadOnlyRecommended, Object& EmbedTrueTypeFonts, Object& SaveNativePictureFormat, Object& SaveFormsData, Object& SaveAsAOCELetter, Object& Encoding, Object& InsertLineBreaks, Object& AllowSubstitutions, Object& LineEnding, Object& AddBiDiMarks)

    Please help to solve this issue.



    Tuesday, April 22, 2014 2:22 PM

All replies

  • If you open such a file in the Word application, as a user, then try to save it using SaveAs, do you get any more detailed information than "A file error has occurred"?

    Is the error consistent: does it always happen with the same files? Does it happen consistently when trying to save to a particular file format?

    It might help if we had information about what values you're passing to the parameters of the SaveAs method (show us the code).

    Which version of Word are you automating?

    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, April 22, 2014 4:44 PM
  • Hi

    Automation Office 2007


                object MISSING = System.Type.Missing;

                object FALSE = false;

                object TRUE = true;

                object COLLAPSE_START = WdCollapseDirection.wdCollapseStart;

                object fileNameObject = @"D:\9-5b4b6755-75a9-4229-a21a-916f448a7dc9.rtf";


                object readOnlyObject = true ;

                Application application = new Application();

                application.Visible = false;

                application.DisplayAlerts = Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone;

                application.DisplayRecentFiles = false;

                application.Options.Pagination = false;


                application.Options.WarnBeforeSavingPrintingSendingMarkup = false;

                application.AutomationSecurity = Microsoft.Office.Core.MsoAutomationSecurity.msoAutomationSecurityForceDisable;

                application.Options.ShowMarkupOpenSave = true;



                    Document document = application.Documents.OpenNoRepairDialog(ref fileNameObject, ref FALSE, ref readOnlyObject, ref FALSE, ref MISSING, ref MISSING, ref MISSING, ref MISSING, ref MISSING, ref MISSING, ref MISSING, ref FALSE, ref TRUE, ref MISSING, ref TRUE, ref MISSING);


                    if (document != null)



                        document.UpdateStylesOnOpen = false;

                        document.ShowGrammaticalErrors = false;

                        document.ShowSpellingErrors = false;

                        document.SpellingChecked = true;

                        document.GrammarChecked = true;

                        document.TrackRevisions = true;

                        document.ShowRevisions = true;

                        document.PrintRevisions = true;

                     //   bool test = document.get_Compatibility(WdCompatibility.wdUseWord97LineBreakingRules);

                        Microsoft.Office.Interop.Word.View view = document.ActiveWindow.View;

                        view.RevisionsView = Microsoft.Office.Interop.Word.WdRevisionsView.wdRevisionsViewFinal;

                        view.ShowRevisionsAndComments = true;

                        foreach (Microsoft.Office.Interop.Word.Style style in document.Styles)


                            if (style.InUse == true)


                                if (style.Type != Microsoft.Office.Interop.Word.WdStyleType.wdStyleTypeCharacter && style.Type != Microsoft.Office.Interop.Word.WdStyleType.wdStyleTypeList && style.Type != Microsoft.Office.Interop.Word.WdStyleType.wdStyleTypeTable)


                                    if (style.AutomaticallyUpdate == true)

                                        style.AutomaticallyUpdate = false;





                    string finalDocx = @"E:\ComException\Convert9-5b4b6755-75a9-4229-a21a-916f448a7dc9.docx";

                    document.SaveAs(finalDocx, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocumentDefault, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);


                catch (Exception ex)





    Above  code working in windows 7 but not working on Windows Server 2008 R2


    Wednesday, April 23, 2014 2:05 PM
  • Just seeing your code is not enough. You also need to provide the other information requested.

    In addition, is your code running locally on a user machine? On a server? Running remotely? Are there sufficient permissions for your code to save on the problem machine?

    Finally, you use Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocumentDefault to specify the file format. Are you certain the default file format on this machine is *.docx? It could be any number of formats and its possible you're running into problems because the file format and the file content and/or file extension don't match. Better to use the more specific file type: wdFormatXMLDocument (or, if that's not available in 2007 - I have 2010 installed on this machine - wdFormatDocument).

    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, April 23, 2014 4:25 PM