Monday, September 12, 2011

Word 2007 document with comments is crashing

My coworker had a document that had around 30 comments and when she'd click on the comment to delete it, Word 2007 would crash.  She mentioned that the comment targets somehow were erased and the comments were orphaned but still in the document.

Word has a recovery mode that did not work.  I tried copy/pasting to a new document which did not work.  Even tried using a VBA macro to delete a comment, then altered it to select and delete these other comments.  That didn't work either.

I know Word 2007 uses the new .docx format, which is really just a zip file container.  So I unzipped the .docx file, dug around in the supporting XML files, and found two files.  There is a document.xml and a comments.xml and inside the comments.xml file is an ID in each node that the document.xml file references.  Pretty simple layout.

In the document.xml file, I searched for "w:comment" and found hits on nodes named
<w:commentRangeStart w:id="3" />
<w:commentRangeEnd w:id="3"/>
<w:commentReference w:id="3"/>

Those nodes match the comments.xml document that has
<w:comment w:id="3">

Furthermore, while searching through the document.xml file, the IDs for problematic comments just happened to have

<w:commentReference w:id="3"/>
but not

<w:commentRangeStart w:id="3" />
<w:commentRangeEnd w:id="3"/>

So... Remove the broken references in document.xml and now there are fully orphaned items in comments.xml so remove those nodes as well.  Save all docs, then rezip the folder and rename to .docx

The doc opens fine, and Word 2007 no longer crashes :)  Woohoo.

Thursday, September 1, 2011

Ensure deploys are not in debug mode



The <deployment retail=”true”/> Switch in Machine.config

If you are a server administrator and want to ensure that no one accidentally deploys an ASP.NET application in production with the <compilation debug=”true”/> switch enabled within the application’s web.config file, one trick you can use with ASP.NET V2.0 is to take advantage of the <deployment> section within your machine.config file.

Specifically, by setting this within your machine.config file:

<configuration>
    <system.web>
          <deployment retail=”true”/>
    </system.web>
</configuration>

You will disable the <compilation debug=”true”/> switch, disable the ability to output trace output in a page, and turn off the ability to show detailed error messages remotely.  Note that these last two items are security best practices you really want to follow (otherwise hackers can learn a lot more about the internals of your application than you should show them).

Setting this switch to true is probably a best practice that any company with formal production servers should follow to ensure that an application always runs with the best possible performance and no security information leakages.  There isn’t a ton of documentation on this switch – but you can learn a little more about it here.