none
Word.Interop Does Not Properly Cleanup Temp WRF File (C#) RRS feed

  • Question

  • Hello everyone,

     

    I am using the Microsoft.Office.Interop.Word assemblies within C# 4.0 to create a Word 2007/2010 document, insert various embedded ole files (.bmps and .pngs pictures, office documents, .txt files, etc) and saving. Everything works fine and the Word process is released and cleaned up as normal, except for the temporary Document-File-Based File that Word creates to “store all OLE objects that belong to unnamed documents, Undo, the Clipboard, and documents whose native formats are not document format (for example, .txt, .rtf, and Word 2.0 documents)” à quoted from http://support.microsoft.com/kb/211632.

     

    I can get to this temporary ~wrfxxxx.tmp file by clicking Start, typing shell:cache, pressing Enter and navigating to the Content.Word folder (must have File Folder Options "Show hidden files, folders, and drives" checked and have "Hide protected operating system files" unchecked). Essentially, I need to clean up these ~wrfxxxx.tmp files or else they continue to grow and take up huge amounts of space on the hard drive, but I have no idea how to track and close/delete/cleanup these file from within code. Can someone please point me in the right direction?

     

     

    Specific files that Word creates

    <script type="text/javascript">// <![CDATA[ loadTOCNode(2, 'moreinformation'); ]]></script> The following tables list some of the specific temporary files that Word creates.

       Files typically created when Word is started                File name

       ------------------------------------------------------------------------

       MS-DOS-based file (to reserve 4 file handles) 0 bytes      ~wrf0000.tmp

       MS-DOS-based scratch file                     0 bytes      ~mfxxxx.tmp

       Compound file - transacted                    0 bytes      ~dftxxxx.tmp

       Compound file - direct                        1536 bytes   ~wrf0001.tmp

       (unnamed non-Word/OLE files)

     

     

       Word recovery files                                        File name

       -----------------------------------------------------------------------

       Temporary file for AutoRecovery                         ~wraxxxx.tmp

       AutoRecovery                      AutoRecovery save of <docname>.asd

     

       Other Word temporary files                                 File name

       -----------------------------------------------------------------------

       Copy of another document                                   ~wrcxxxx.tmp

       Word document                                              ~wrdxxxx.tmp

       Temp document file                                         ~wrfxxxx.tmp

       Dictionary                                                 ~wrixxxx.tmp

       Clipboard                                                  ~wrlxxxx.tmp

       Macro                                                      ~wrmxxxx.tmp

       Word OLE document                                          ~wroxxxx.tmp

       Scratch file                                               ~wrsxxxx.tmp

       Converted (foreign) document                               ~wrvxxxx.tmp

    Monday, June 20, 2011 11:27 PM

Answers

  • Hello,

    http://support.microsoft.com/kb/211632 states "The temporary files only exist during the current session of Word. When Word is shut down in a normal fashion, all temporary files are first closed and then deleted."

    I suggest that you check you close Word correctly. Make sure that WINWORD.EXE doesn't hang in the Task Manager window before and after you run your code.


    Regards from Belarus (GMT + 2),

    Andrei Smolin
    Add-in Express Team Leader
    Friday, July 8, 2011 8:39 AM