<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" version="2.0">
  <channel>
    <title>Samurai Programmer.com - OpenXML</title>
    <link>http://www.samuraiprogrammer.com/blog/</link>
    <description>I know kung fu</description>
    <language>en-us</language>
    <copyright>Greg Varveris</copyright>
    <lastBuildDate>Sat, 03 Sep 2011 16:56:55 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.9074.18820</generator>
    <managingEditor>greg@samuraiprogrammer.com</managingEditor>
    <webMaster>greg@samuraiprogrammer.com</webMaster>
    <item>
      <trackback:ping>http://www.samuraiprogrammer.com/blog/Trackback.aspx?guid=e4740c06-15bc-4ad7-a99a-735725fb5f1c</trackback:ping>
      <pingback:server>http://www.samuraiprogrammer.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.samuraiprogrammer.com/blog/PermaLink,guid,e4740c06-15bc-4ad7-a99a-735725fb5f1c.aspx</pingback:target>
      <dc:creator>Greg Varveris</dc:creator>
      <wfw:comment>http://www.samuraiprogrammer.com/blog/CommentView,guid,e4740c06-15bc-4ad7-a99a-735725fb5f1c.aspx</wfw:comment>
      <wfw:commentRss>http://www.samuraiprogrammer.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=e4740c06-15bc-4ad7-a99a-735725fb5f1c</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
So, many apologies for dropping off the face of the blogosphere lately.  Fortunately
(or unfortunately, depending on your perspective), I’ve been really busy at work. 
I’ve been working on some really cool things that I hope I’ll be able to talk about
publicly soon.  For now, though, I wanted to pass on something that I haven’t
seen documented in other places that actually helped me quite a bit lately.  
</p>
        <p>
So, for those of you that generate Word documents via the OpenXML (or any other of
a variety of methods), you may have come across something like this when you opened
up a document you just generated:
</p>
        <p>
          <a href="http://www.samuraiprogrammer.com/blog/content/binary/Windows-Live-Writer/9b44f80892c4_9194/image_2.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.samuraiprogrammer.com/blog/content/binary/Windows-Live-Writer/9b44f80892c4_9194/image_thumb.png" width="397" height="167" />
          </a>
        </p>
        <p>
There are some problems with this message but the big one is that it just says “Line:
1, Column: 0”.  Not exactly a map to the error.  As a result, you may have
stared at this message for a long time and wondered – “how the heck do I fix this? 
What is the real problem?”.  Well, let me show you a really quick and easy way
of getting more information than what is initially provided.
</p>
        <h2>Step 1:  Change the extension from docx to zip
</h2>
        <p>
As you may or may not know, all OpenXML documents (or Office documents since Office
2007) are actually zip files at their core. That means you can just crack them open
and peer inside. 
</p>
        <p>
          <a href="http://www.samuraiprogrammer.com/blog/content/binary/Windows-Live-Writer/9b44f80892c4_9194/image_4.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.samuraiprogrammer.com/blog/content/binary/Windows-Live-Writer/9b44f80892c4_9194/image_thumb_1.png" width="588" height="77" />
          </a>
        </p>
        <p>
See the difference?  Easy!
</p>
        <h2>Step 2:  Extract the zip file to a folder
</h2>
        <p>
Once again, pretty straight forward.  Once you extract the zip file above, you
should see a structure like the following:
</p>
        <p>
          <a href="http://www.samuraiprogrammer.com/blog/content/binary/Windows-Live-Writer/9b44f80892c4_9194/image_6.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.samuraiprogrammer.com/blog/content/binary/Windows-Live-Writer/9b44f80892c4_9194/image_thumb_2.png" width="503" height="162" />
          </a>
        </p>
        <p>
Now, from here – you’ll be able to locate the file referenced in that cryptic error
message above.  
</p>
        <h2>Step 3:  Find the file that’s causing the problem
</h2>
        <p>
In the example above, the message states that the problem lies with the file “/word/document.xml”
so just navigate to the “word” folder and find the “document.xml”.
</p>
        <p>
          <a href="http://www.samuraiprogrammer.com/blog/content/binary/Windows-Live-Writer/9b44f80892c4_9194/image_8.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.samuraiprogrammer.com/blog/content/binary/Windows-Live-Writer/9b44f80892c4_9194/image_thumb_3.png" width="594" height="305" />
          </a>
        </p>
        <h2>Step 4:  Open and format the file in Visual Studio
</h2>
        <p>
One of the great features of Visual Studio is that it can format an XML file for you. 
So, in our case, the document.xml file is natively just one big line:
</p>
        <p>
          <a href="http://www.samuraiprogrammer.com/blog/content/binary/Windows-Live-Writer/9b44f80892c4_9194/image_10.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.samuraiprogrammer.com/blog/content/binary/Windows-Live-Writer/9b44f80892c4_9194/image_thumb_4.png" width="644" height="57" />
          </a>
        </p>
        <p>
Incidentally, this is why the message always states “Line 1,…” in the error message. 
As far as Word is concerned, the problem IS on the first line.  Fortunately for
us, though, Word can take that single line file and format it for us.  Just use
the Edit &gt; Advanced &gt; Format Document option in Visual Studio:
</p>
        <p>
          <a href="http://www.samuraiprogrammer.com/blog/content/binary/Windows-Live-Writer/9b44f80892c4_9194/image_12.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.samuraiprogrammer.com/blog/content/binary/Windows-Live-Writer/9b44f80892c4_9194/image_thumb_5.png" width="615" height="372" />
          </a>
        </p>
        <p>
That will then format the XML and make it look closer to:
</p>
        <p>
          <a href="http://www.samuraiprogrammer.com/blog/content/binary/Windows-Live-Writer/9b44f80892c4_9194/image_14.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.samuraiprogrammer.com/blog/content/binary/Windows-Live-Writer/9b44f80892c4_9194/image_thumb_6.png" width="673" height="296" />
          </a>
        </p>
        <h2>Step 5:  Recreate the Word doc and get the additional information
</h2>
        <p>
Now that you have the file formatted appropriately, you can just re-create the Word
document and re-open it.  For this, just go back to the root of the document,
select all the files/folders and then zip it back up:
</p>
        <p>
          <a href="http://www.samuraiprogrammer.com/blog/content/binary/Windows-Live-Writer/9b44f80892c4_9194/image_16.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.samuraiprogrammer.com/blog/content/binary/Windows-Live-Writer/9b44f80892c4_9194/image_thumb_7.png" width="668" height="399" />
          </a>
        </p>
        <p>
Once it’s zipped back up again, just change the extension from zip to docx and re-open
the file.  When you do so, you’ll see the following:
</p>
        <p>
          <a href="http://www.samuraiprogrammer.com/blog/content/binary/Windows-Live-Writer/9b44f80892c4_9194/image_18.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.samuraiprogrammer.com/blog/content/binary/Windows-Live-Writer/9b44f80892c4_9194/image_thumb_8.png" width="397" height="167" />
          </a>
        </p>
        <p>
          <strong>Note that now, you’ll see that it says “Line: 5667, Column: 0”</strong> –
which will point to the exact line causing the problem – which allows you to just
go back to the “document.xml” file you already have open in Visual Studio to see the
problem.  In our case:
</p>
        <p>
          <a href="http://www.samuraiprogrammer.com/blog/content/binary/Windows-Live-Writer/9b44f80892c4_9194/image_20.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.samuraiprogrammer.com/blog/content/binary/Windows-Live-Writer/9b44f80892c4_9194/image_thumb_9.png" width="494" height="171" />
          </a>
        </p>
        <p>
Note that this won’t magically fix your problem.  You’ll still need to examine
the WordML to figure out the problem – but at least you know where to go.  And
knowing is half the battle!  
</p>
        <p>
That’s all for now and I will be back with some more developer stuff soon.  
</p>
        <p>
Until next time!
</p>
      </body>
      <title>Getting more information from the Word error box when troubleshooting OpenXML / WordML issues</title>
      <guid isPermaLink="false">http://www.samuraiprogrammer.com/blog/PermaLink,guid,e4740c06-15bc-4ad7-a99a-735725fb5f1c.aspx</guid>
      <link>http://www.samuraiprogrammer.com/blog/2011/09/03/GettingMoreInformationFromTheWordErrorBoxWhenTroubleshootingOpenXMLWordMLIssues.aspx</link>
      <pubDate>Sat, 03 Sep 2011 16:56:55 GMT</pubDate>
      <description>&lt;p&gt;
So, many apologies for dropping off the face of the blogosphere lately.&amp;#160; Fortunately
(or unfortunately, depending on your perspective), I’ve been really busy at work.&amp;#160;
I’ve been working on some really cool things that I hope I’ll be able to talk about
publicly soon.&amp;#160; For now, though, I wanted to pass on something that I haven’t
seen documented in other places that actually helped me quite a bit lately.&amp;#160; 
&lt;/p&gt;
&lt;p&gt;
So, for those of you that generate Word documents via the OpenXML (or any other of
a variety of methods), you may have come across something like this when you opened
up a document you just generated:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.samuraiprogrammer.com/blog/content/binary/Windows-Live-Writer/9b44f80892c4_9194/image_2.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.samuraiprogrammer.com/blog/content/binary/Windows-Live-Writer/9b44f80892c4_9194/image_thumb.png" width="397" height="167" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
There are some problems with this message but the big one is that it just says “Line:
1, Column: 0”.&amp;#160; Not exactly a map to the error.&amp;#160; As a result, you may have
stared at this message for a long time and wondered – “how the heck do I fix this?&amp;#160;
What is the real problem?”.&amp;#160; Well, let me show you a really quick and easy way
of getting more information than what is initially provided.
&lt;/p&gt;
&lt;h2&gt;Step 1:&amp;#160; Change the extension from docx to zip
&lt;/h2&gt;
&lt;p&gt;
As you may or may not know, all OpenXML documents (or Office documents since Office
2007) are actually zip files at their core. That means you can just crack them open
and peer inside. 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.samuraiprogrammer.com/blog/content/binary/Windows-Live-Writer/9b44f80892c4_9194/image_4.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.samuraiprogrammer.com/blog/content/binary/Windows-Live-Writer/9b44f80892c4_9194/image_thumb_1.png" width="588" height="77" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
See the difference?&amp;#160; Easy!
&lt;/p&gt;
&lt;h2&gt;Step 2:&amp;#160; Extract the zip file to a folder
&lt;/h2&gt;
&lt;p&gt;
Once again, pretty straight forward.&amp;#160; Once you extract the zip file above, you
should see a structure like the following:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.samuraiprogrammer.com/blog/content/binary/Windows-Live-Writer/9b44f80892c4_9194/image_6.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.samuraiprogrammer.com/blog/content/binary/Windows-Live-Writer/9b44f80892c4_9194/image_thumb_2.png" width="503" height="162" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Now, from here – you’ll be able to locate the file referenced in that cryptic error
message above.&amp;#160; 
&lt;/p&gt;
&lt;h2&gt;Step 3:&amp;#160; Find the file that’s causing the problem
&lt;/h2&gt;
&lt;p&gt;
In the example above, the message states that the problem lies with the file “/word/document.xml”
so just navigate to the “word” folder and find the “document.xml”.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.samuraiprogrammer.com/blog/content/binary/Windows-Live-Writer/9b44f80892c4_9194/image_8.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.samuraiprogrammer.com/blog/content/binary/Windows-Live-Writer/9b44f80892c4_9194/image_thumb_3.png" width="594" height="305" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;h2&gt;Step 4:&amp;#160; Open and format the file in Visual Studio
&lt;/h2&gt;
&lt;p&gt;
One of the great features of Visual Studio is that it can format an XML file for you.&amp;#160;
So, in our case, the document.xml file is natively just one big line:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.samuraiprogrammer.com/blog/content/binary/Windows-Live-Writer/9b44f80892c4_9194/image_10.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.samuraiprogrammer.com/blog/content/binary/Windows-Live-Writer/9b44f80892c4_9194/image_thumb_4.png" width="644" height="57" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Incidentally, this is why the message always states “Line 1,…” in the error message.&amp;#160;
As far as Word is concerned, the problem IS on the first line.&amp;#160; Fortunately for
us, though, Word can take that single line file and format it for us.&amp;#160; Just use
the Edit &amp;gt; Advanced &amp;gt; Format Document option in Visual Studio:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.samuraiprogrammer.com/blog/content/binary/Windows-Live-Writer/9b44f80892c4_9194/image_12.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.samuraiprogrammer.com/blog/content/binary/Windows-Live-Writer/9b44f80892c4_9194/image_thumb_5.png" width="615" height="372" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
That will then format the XML and make it look closer to:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.samuraiprogrammer.com/blog/content/binary/Windows-Live-Writer/9b44f80892c4_9194/image_14.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.samuraiprogrammer.com/blog/content/binary/Windows-Live-Writer/9b44f80892c4_9194/image_thumb_6.png" width="673" height="296" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;h2&gt;Step 5:&amp;#160; Recreate the Word doc and get the additional information
&lt;/h2&gt;
&lt;p&gt;
Now that you have the file formatted appropriately, you can just re-create the Word
document and re-open it.&amp;#160; For this, just go back to the root of the document,
select all the files/folders and then zip it back up:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.samuraiprogrammer.com/blog/content/binary/Windows-Live-Writer/9b44f80892c4_9194/image_16.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.samuraiprogrammer.com/blog/content/binary/Windows-Live-Writer/9b44f80892c4_9194/image_thumb_7.png" width="668" height="399" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Once it’s zipped back up again, just change the extension from zip to docx and re-open
the file.&amp;#160; When you do so, you’ll see the following:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.samuraiprogrammer.com/blog/content/binary/Windows-Live-Writer/9b44f80892c4_9194/image_18.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.samuraiprogrammer.com/blog/content/binary/Windows-Live-Writer/9b44f80892c4_9194/image_thumb_8.png" width="397" height="167" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Note that now, you’ll see that it says “Line: 5667, Column: 0”&lt;/strong&gt; –
which will point to the exact line causing the problem – which allows you to just
go back to the “document.xml” file you already have open in Visual Studio to see the
problem.&amp;#160; In our case:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.samuraiprogrammer.com/blog/content/binary/Windows-Live-Writer/9b44f80892c4_9194/image_20.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.samuraiprogrammer.com/blog/content/binary/Windows-Live-Writer/9b44f80892c4_9194/image_thumb_9.png" width="494" height="171" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Note that this won’t magically fix your problem.&amp;#160; You’ll still need to examine
the WordML to figure out the problem – but at least you know where to go.&amp;#160; And
knowing is half the battle!&amp;#160; 
&lt;/p&gt;
&lt;p&gt;
That’s all for now and I will be back with some more developer stuff soon.&amp;#160; 
&lt;/p&gt;
&lt;p&gt;
Until next time!
&lt;/p&gt;</description>
      <comments>http://www.samuraiprogrammer.com/blog/CommentView,guid,e4740c06-15bc-4ad7-a99a-735725fb5f1c.aspx</comments>
      <category>OpenXML</category>
      <category>Troubleshooting</category>
    </item>
    <item>
      <trackback:ping>http://www.samuraiprogrammer.com/blog/Trackback.aspx?guid=471f190b-cdf8-4695-b29d-684d3e55ce17</trackback:ping>
      <pingback:server>http://www.samuraiprogrammer.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.samuraiprogrammer.com/blog/PermaLink,guid,471f190b-cdf8-4695-b29d-684d3e55ce17.aspx</pingback:target>
      <dc:creator>Greg Varveris</dc:creator>
      <wfw:comment>http://www.samuraiprogrammer.com/blog/CommentView,guid,471f190b-cdf8-4695-b29d-684d3e55ce17.aspx</wfw:comment>
      <wfw:commentRss>http://www.samuraiprogrammer.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=471f190b-cdf8-4695-b29d-684d3e55ce17</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="http://www.samuraiprogrammer.com/blog/content/binary/WindowsLiveWriter/OpenXMLRefreshafieldwhenthedocumentisope_10A90/logo_Office_2010_2.jpg">
            <img style="border-right-width: 0px; margin: 10px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="logo_Office_2010" border="0" alt="logo_Office_2010" align="left" src="http://www.samuraiprogrammer.com/blog/content/binary/WindowsLiveWriter/OpenXMLRefreshafieldwhenthedocumentisope_10A90/logo_Office_2010_thumb.jpg" width="240" height="85" />
          </a> I
was working on an internal project a bit ago and one of the requirements was to implement
a fancy Word document.  The idea was that all of the editing of the text/code
samples/etc. would be done in the application and then the user could just export
it to Word to put any finishing touches and send off to the customer.  The final
report needed to include section headers, page breaks, a table of contents, etc. 
There are a number of ways we could have accomplished the task.  <a href="http://msdn.microsoft.com/en-us/library/kw65a0we(VS.80).aspx" target="_blank">There’s
the Word automation stuff that relies upon a COM based API</a>, there’s the method
of just creating an HTML document and loading that into Word and then finally <a href="http://openxmldeveloper.org/default.aspx" target="_blank">there’s
the Open XML API</a>.  Now, someone had hacked up a version of this export functionality
previously using the Word automation stuff but considering we’re often dealing with
1,000+ page documents – it turned out to be a little slow.  <a href="http://support.microsoft.com/kb/257757" target="_blank">Also,
there are some restrictions around using the automation libraries in a server context.</a> 
Lastly, since my OpenXML kung-fu is strong, I thought I would take the opportunity
to implement a better, more flexible and much faster solution.  <a href="http://blogs.msdn.com/b/brian_jones/" target="_blank">For
those just starting out, Brian and Zeyad’s excellent blog on the topic is invaluable</a>.  
</p>
        <p>
One of the requirements for the export operation was to have Word automagically refresh
the table of contents (and other fields) the first time the document is opened. 
This was something that took a bit of time to research but you really end up with
2 options:
</p>
        <ul>
          <li>
            <a href="http://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.updatefieldsonopen.aspx" target="_blank">w:updateFields
– A document-level element that will refresh all of the fields when the document is
opened</a>. 
<br /></li>
          <li>
            <a href="http://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.simplefield.dirty.aspx" target="_blank">w:dirty
– A field-level attribute that will refresh ONLY the field you specify when the document
is opened</a>. 
</li>
        </ul>
        <h2>
        </h2>
        <h2>w:updateFields Element
</h2>
        <p>
The “w:updateFields” element is a document-level element that is set in the document
settings part and tells Word to update all of the fields in the document:
</p>
        <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; font-size: 8pt; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <span style="color: #0000ff">&lt;?</span>
            <span style="color: #800000">xml</span>
            <span style="color: #ff0000">version</span>
            <span style="color: #0000ff">="1.0"</span>
            <span style="color: #ff0000">encoding</span>
            <span style="color: #0000ff">="utf-8"</span>
            <span style="color: #ff0000">standalone</span>
            <span style="color: #0000ff">="yes"</span>?<span style="color: #0000ff">&gt;</span><br /><span style="color: #0000ff">&lt;</span><span style="color: #800000">w:settings</span> …<span style="color: #0000ff">&gt;</span><br /><span style="color: #0000ff">&lt;</span><span style="color: #800000">w:updateFields</span><span style="color: #ff0000">w:val</span><span style="color: #0000ff">="true"</span><span style="color: #0000ff">/&gt;</span><br />
…<br /><span style="color: #0000ff">&lt;/</span><span style="color: #800000">w:settings</span><span style="color: #0000ff">&gt;</span><br /></pre>
          <br />
        </div>
        <p>
If you’re wondering what the document settings part is – just rename a Word doc from
“<strong>blah.docx</strong>” to “<strong>blah.docx.zip</strong>” and extract it to
a folder on your computer.  In the new folder is a directory called “word”. 
In that directory, you should see a file called “settings.xml”:
</p>
        <p>
          <a href="http://www.samuraiprogrammer.com/blog/content/binary/WindowsLiveWriter/OpenXMLRefreshafieldwhenthedocumentisope_10A90/image_4.png">
            <img style="border-right-width: 0px; margin: 10px auto; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.samuraiprogrammer.com/blog/content/binary/WindowsLiveWriter/OpenXMLRefreshafieldwhenthedocumentisope_10A90/image_thumb_1.png" width="392" height="136" />
          </a> In
that file are all of the document level settings for your docx.  <a href="http://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.settings.aspx" target="_blank">There’s
some really great stuff in here</a>.  
</p>
        <p>
If you’d like to use the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=c6e744e5-36e9-45f5-8d8c-331df206e0d0&amp;DisplayLang=en" target="_blank">OpenXML
SDK to set that value</a> (and you’d be crazy not to), here’s some sample code:
</p>
        <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; font-size: 8pt; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <span style="color: #0000ff">using</span> (WordprocessingDocument
document = WordprocessingDocument.Open(path, <span style="color: #0000ff">true</span>))<br />
{<br /><br />
DocumentSettingsPart settingsPart = 
<br />
document.MainDocumentPart.GetPartsOfType&lt;DocumentSettingsPart&gt;().First();<br /><br /><span style="color: #008000">// Create object to update fields on open</span><br />
UpdateFieldsOnOpen updateFields = <span style="color: #0000ff">new</span> UpdateFieldsOnOpen();<br />
updateFields.Val = <span style="color: #0000ff">new</span> DocumentFormat.OpenXml.OnOffValue(<span style="color: #0000ff">true</span>);<br /><br /><span style="color: #008000">// Insert object into settings part.</span><br />
settingsPart.Settings.PrependChild&lt;UpdateFieldsOnOpen&gt;(updateFields);<br />
settingsPart.Settings.Save();<br /><br />
}</pre>
          <br />
        </div>
        <h2>w:dirty Attribute
</h2>
        <p>
This attribute is applied to the field you would like to have refreshed when the document
is opened in Word.  It tells Word to only refresh this field the next time the
document is opened.  For example, if you want to apply it to a field like your
table of contents, just find the w:fldChar and add that attribute:
</p>
        <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; font-size: 8pt; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <span style="color: #0000ff">&lt;</span>
            <span style="color: #800000">w:r</span>
            <span style="color: #0000ff">&gt;</span>
            <br />
            <span style="color: #0000ff">&lt;</span>
            <span style="color: #800000">w:fldChar</span>
            <span style="color: #ff0000">w:fldCharType</span>
            <span style="color: #0000ff">="begin"</span>
            <span style="color: #ff0000">w:dirty</span>
            <span style="color: #0000ff">="true"</span>
            <span style="color: #0000ff">/&gt;</span>
            <br />
            <span style="color: #0000ff">&lt;/</span>
            <span style="color: #800000">w:r</span>
            <span style="color: #0000ff">&gt;</span>
          </pre>
          <br />
        </div>
        <p>
For a simple field, like the document author, you’ll want to add it to the w:fldSimple
element, like so:
</p>
        <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; font-size: 8pt; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <span style="color: #0000ff">&lt;</span>
            <span style="color: #800000">w:fldSimple</span>
            <span style="color: #ff0000">w:instr</span>
            <span style="color: #0000ff">="AUTHOR
\* Upper \* MERGEFORMAT"</span>
            <br />
            <span style="color: #ff0000">w:dirty</span>
            <span style="color: #0000ff">="true"</span>
            <span style="color: #0000ff">&gt;</span>
            <br />
            <span style="color: #0000ff">&lt;</span>
            <span style="color: #800000">w:r</span>
            <span style="color: #0000ff">&gt;</span>
            <br />
...<br /><span style="color: #0000ff">&lt;/</span><span style="color: #800000">w:r</span><span style="color: #0000ff">&gt;</span><br /><span style="color: #0000ff">&lt;/</span><span style="color: #800000">w:fldSimple</span><span style="color: #0000ff">&gt;</span></pre>
          <br />
        </div>
        <h2>A caveat or two
</h2>
        <p>
          <strong>Both of these methods will work just fine in Word 2010.</strong>  
</p>
        <p>
In Word 2007, though, you need to clear out the contents of the field before the user
opens the document.  For example, with a table of contents, Word will normally
cache the contents of the TOC in the fldChar element.  This is good, normally,
but here it causes a problem.  
</p>
        <p>
For example, in a very simple test document, you would see the following cached data
(i.e.:  Heading 1, Heading 2, etc.):
</p>
        <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; font-size: 8pt; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <span style="color: #0000ff">&lt;</span>
            <span style="color: #800000">w:p</span>
            <span style="color: #ff0000">w:rsidR</span>
            <span style="color: #0000ff">="00563999"</span>
            <span style="color: #ff0000">w:rsidRDefault</span>
            <span style="color: #0000ff">="00050B09"</span>
            <span style="color: #0000ff">&gt;</span>
            <br />
...<br /><span style="color: #0000ff">&lt;</span><span style="color: #800000">w:r</span><span style="color: #0000ff">&gt;</span><br /><span style="color: #0000ff">&lt;</span><span style="color: #800000">w:fldChar</span><span style="color: #ff0000">w:fldCharType</span><span style="color: #0000ff">="begin"</span><span style="color: #0000ff">/&gt;</span><br /><span style="color: #0000ff">&lt;/</span><span style="color: #800000">w:r</span><span style="color: #0000ff">&gt;</span><br /><span style="color: #0000ff">&lt;</span><span style="color: #800000">w:r</span><span style="color: #ff0000">w:rsidR</span><span style="color: #0000ff">="00563999"</span><span style="color: #0000ff">&gt;</span><br /><span style="color: #0000ff">&lt;</span><span style="color: #800000">w:instrText</span><span style="color: #ff0000">xml:space</span><span style="color: #0000ff">="preserve"</span><span style="color: #0000ff">&gt;</span> TOC
\* MERGEFORMAT <span style="color: #0000ff">&lt;/</span><span style="color: #800000">w:instrText</span><span style="color: #0000ff">&gt;</span><br /><span style="color: #0000ff">&lt;/</span><span style="color: #800000">w:r</span><span style="color: #0000ff">&gt;</span><br /><span style="color: #0000ff">&lt;/</span><span style="color: #800000">w:p</span><span style="color: #0000ff">&gt;</span><br /><span style="color: #0000ff">&lt;</span><span style="color: #800000">w:p</span><span style="color: #ff0000">w:rsidR</span><span style="color: #0000ff">="00F77370"</span><span style="color: #ff0000">w:rsidRDefault</span><span style="color: #0000ff">="00F77370"</span><span style="color: #0000ff">&gt;</span><br />
...<br /><span style="color: #0000ff">&lt;</span><span style="color: #800000">w:r</span><span style="color: #0000ff">&gt;</span><br />
...<br /><span style="color: #0000ff">&lt;</span><span style="color: #800000">w:t</span><span style="color: #0000ff">&gt;</span>Heading
1<span style="color: #0000ff">&lt;/</span><span style="color: #800000">w:t</span><span style="color: #0000ff">&gt;</span><br /><span style="color: #0000ff">&lt;/</span><span style="color: #800000">w:r</span><span style="color: #0000ff">&gt;</span><br />
...<br /><span style="color: #0000ff">&lt;/</span><span style="color: #800000">w:p</span><span style="color: #0000ff">&gt;</span><br /><span style="color: #0000ff">&lt;</span><span style="color: #800000">w:p</span><span style="color: #ff0000">w:rsidR</span><span style="color: #0000ff">="00F77370"</span><span style="color: #ff0000">w:rsidRDefault</span><span style="color: #0000ff">="00F77370"</span><span style="color: #0000ff">&gt;</span><br />
...<br /><span style="color: #0000ff">&lt;</span><span style="color: #800000">w:r</span><span style="color: #0000ff">&gt;</span><br />
...<br /><span style="color: #0000ff">&lt;</span><span style="color: #800000">w:t</span><span style="color: #0000ff">&gt;</span>Heading
2<span style="color: #0000ff">&lt;/</span><span style="color: #800000">w:t</span><span style="color: #0000ff">&gt;</span><br /><span style="color: #0000ff">&lt;/</span><span style="color: #800000">w:r</span><span style="color: #0000ff">&gt;</span><br />
...<br /><span style="color: #0000ff">&lt;/</span><span style="color: #800000">w:p</span><span style="color: #0000ff">&gt;</span><br /><span style="color: #0000ff">&lt;</span><span style="color: #800000">w:p</span><span style="color: #ff0000">w:rsidR</span><span style="color: #0000ff">="00F77370"</span><span style="color: #ff0000">w:rsidRDefault</span><span style="color: #0000ff">="00F77370"</span><span style="color: #0000ff">&gt;</span><br />
...<br /><span style="color: #0000ff">&lt;</span><span style="color: #800000">w:r</span><span style="color: #0000ff">&gt;</span><br /><span style="color: #0000ff">&lt;</span><span style="color: #800000">w:rPr</span><span style="color: #0000ff">&gt;</span><br /><span style="color: #0000ff">&lt;</span><span style="color: #800000">w:noProof</span><span style="color: #0000ff">/&gt;</span><br /><span style="color: #0000ff">&lt;/</span><span style="color: #800000">w:rPr</span><span style="color: #0000ff">&gt;</span><br /><span style="color: #0000ff">&lt;</span><span style="color: #800000">w:fldChar</span><span style="color: #ff0000">w:fldCharType</span><span style="color: #0000ff">="end"</span><span style="color: #0000ff">/&gt;</span><br /><span style="color: #0000ff">&lt;/</span><span style="color: #800000">w:r</span><span style="color: #0000ff">&gt;</span><br /><span style="color: #0000ff">&lt;/</span><span style="color: #800000">w:p</span><span style="color: #0000ff">&gt;</span></pre>
          <br />
        </div>
        <p>
After you clear out the <a href="http://www.urbandictionary.com/define.php?term=schmutz" target="_blank">schmutz</a>,
you end up with just the begin element, the definition of the TOC and the end element:
</p>
        <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; font-size: 8pt; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
          <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <span style="color: #0000ff">&lt;</span>
            <span style="color: #800000">w:p</span>
            <span style="color: #ff0000">w:rsidR</span>
            <span style="color: #0000ff">="00563999"</span>
            <span style="color: #ff0000">w:rsidRDefault</span>
            <span style="color: #0000ff">="00563999"</span>
            <span style="color: #0000ff">&gt;</span>
            <br />
...<br /><span style="color: #0000ff">&lt;</span><span style="color: #800000">w:r</span><span style="color: #0000ff">&gt;</span><br /><span style="color: #0000ff">&lt;</span><span style="color: #800000">w:fldChar</span><span style="color: #ff0000">w:fldCharType</span><span style="color: #0000ff">="begin"</span><span style="color: #0000ff">/&gt;</span><br /><span style="color: #0000ff">&lt;/</span><span style="color: #800000">w:r</span><span style="color: #0000ff">&gt;</span><br /><span style="color: #0000ff">&lt;</span><span style="color: #800000">w:r</span><span style="color: #0000ff">&gt;</span><br /><span style="color: #0000ff">&lt;</span><span style="color: #800000">w:instrText</span><span style="color: #ff0000">xml:space</span><span style="color: #0000ff">="preserve"</span><span style="color: #0000ff">&gt;</span> TOC
\* MERGEFORMAT <span style="color: #0000ff">&lt;/</span><span style="color: #800000">w:instrText</span><span style="color: #0000ff">&gt;</span><br /><span style="color: #0000ff">&lt;/</span><span style="color: #800000">w:r</span><span style="color: #0000ff">&gt;</span><br /><span style="color: #0000ff">&lt;/</span><span style="color: #800000">w:p</span><span style="color: #0000ff">&gt;</span><br /><span style="color: #0000ff">&lt;</span><span style="color: #800000">w:p</span><span style="color: #ff0000">w:rsidR</span><span style="color: #0000ff">="00B63C3C"</span><span style="color: #ff0000">w:rsidRDefault</span><span style="color: #0000ff">="00563999"</span><span style="color: #ff0000">w:rsidP</span><span style="color: #0000ff">="00B63C3C"</span><span style="color: #0000ff">&gt;</span><br /><span style="color: #0000ff">&lt;</span><span style="color: #800000">w:r</span><span style="color: #0000ff">&gt;</span><br /><span style="color: #0000ff">&lt;</span><span style="color: #800000">w:fldChar</span><span style="color: #ff0000">w:fldCharType</span><span style="color: #0000ff">="end"</span><span style="color: #0000ff">/&gt;</span><br /><span style="color: #0000ff">&lt;/</span><span style="color: #800000">w:r</span><span style="color: #0000ff">&gt;</span><br />
...<br /><span style="color: #0000ff">&lt;/</span><span style="color: #800000">w:p</span><span style="color: #0000ff">&gt;</span></pre>
          <br />
        </div>
        <p>
Once you’ve made the updates, you can safely open up your file in Word 2007 and your
fields will update when the document opens.
</p>
        <p>
          <a href="http://blogs.msdn.com/b/brian_jones/" target="_blank">Big thanks for Zeyad
for his tip on trimming out the schmutz.</a>
        </p>
        <h4>Just to stress, this is improved in Word 2010 and you no longer need to clear
out the cached data in your fields.
</h4>
        <p>
Enjoy!
</p>
      </body>
      <title>OpenXML: How to refresh a field when the document is opened</title>
      <guid isPermaLink="false">http://www.samuraiprogrammer.com/blog/PermaLink,guid,471f190b-cdf8-4695-b29d-684d3e55ce17.aspx</guid>
      <link>http://www.samuraiprogrammer.com/blog/2010/08/09/OpenXMLHowToRefreshAFieldWhenTheDocumentIsOpened.aspx</link>
      <pubDate>Mon, 09 Aug 2010 06:09:32 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a href="http://www.samuraiprogrammer.com/blog/content/binary/WindowsLiveWriter/OpenXMLRefreshafieldwhenthedocumentisope_10A90/logo_Office_2010_2.jpg"&gt;&lt;img style="border-right-width: 0px; margin: 10px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="logo_Office_2010" border="0" alt="logo_Office_2010" align="left" src="http://www.samuraiprogrammer.com/blog/content/binary/WindowsLiveWriter/OpenXMLRefreshafieldwhenthedocumentisope_10A90/logo_Office_2010_thumb.jpg" width="240" height="85" /&gt;&lt;/a&gt; I
was working on an internal project a bit ago and one of the requirements was to implement
a fancy Word document.&amp;#160; The idea was that all of the editing of the text/code
samples/etc. would be done in the application and then the user could just export
it to Word to put any finishing touches and send off to the customer.&amp;#160; The final
report needed to include section headers, page breaks, a table of contents, etc.&amp;#160;
There are a number of ways we could have accomplished the task.&amp;#160; &lt;a href="http://msdn.microsoft.com/en-us/library/kw65a0we(VS.80).aspx" target="_blank"&gt;There’s
the Word automation stuff that relies upon a COM based API&lt;/a&gt;, there’s the method
of just creating an HTML document and loading that into Word and then finally &lt;a href="http://openxmldeveloper.org/default.aspx" target="_blank"&gt;there’s
the Open XML API&lt;/a&gt;.&amp;#160; Now, someone had hacked up a version of this export functionality
previously using the Word automation stuff but considering we’re often dealing with
1,000+ page documents – it turned out to be a little slow.&amp;#160; &lt;a href="http://support.microsoft.com/kb/257757" target="_blank"&gt;Also,
there are some restrictions around using the automation libraries in a server context.&lt;/a&gt;&amp;#160;
Lastly, since my OpenXML kung-fu is strong, I thought I would take the opportunity
to implement a better, more flexible and much faster solution.&amp;#160; &lt;a href="http://blogs.msdn.com/b/brian_jones/" target="_blank"&gt;For
those just starting out, Brian and Zeyad’s excellent blog on the topic is invaluable&lt;/a&gt;.&amp;#160; 
&lt;/p&gt;
&lt;p&gt;
One of the requirements for the export operation was to have Word automagically refresh
the table of contents (and other fields) the first time the document is opened.&amp;#160;
This was something that took a bit of time to research but you really end up with
2 options:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href="http://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.updatefieldsonopen.aspx" target="_blank"&gt;w:updateFields
– A document-level element that will refresh all of the fields when the document is
opened&lt;/a&gt;. 
&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.simplefield.dirty.aspx" target="_blank"&gt;w:dirty
– A field-level attribute that will refresh ONLY the field you specify when the document
is opened&lt;/a&gt;. 
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
&lt;/h2&gt;
&lt;h2&gt;w:updateFields Element
&lt;/h2&gt;
&lt;p&gt;
The “w:updateFields” element is a document-level element that is set in the document
settings part and tells Word to update all of the fields in the document:
&lt;/p&gt;
&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; font-size: 8pt; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;?&lt;/span&gt;&lt;span style="color: #800000"&gt;xml&lt;/span&gt; &lt;span style="color: #ff0000"&gt;version&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;1.0&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;encoding&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;utf-8&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;standalone&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;yes&amp;quot;&lt;/span&gt;?&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;w:settings&lt;/span&gt; …&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;w:updateFields&lt;/span&gt; &lt;span style="color: #ff0000"&gt;w:val&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;br /&gt;
…&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;w:settings&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;br /&gt;
&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
If you’re wondering what the document settings part is – just rename a Word doc from
“&lt;strong&gt;blah.docx&lt;/strong&gt;” to “&lt;strong&gt;blah.docx.zip&lt;/strong&gt;” and extract it to
a folder on your computer.&amp;#160; In the new folder is a directory called “word”.&amp;#160;
In that directory, you should see a file called “settings.xml”:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.samuraiprogrammer.com/blog/content/binary/WindowsLiveWriter/OpenXMLRefreshafieldwhenthedocumentisope_10A90/image_4.png"&gt;&lt;img style="border-right-width: 0px; margin: 10px auto; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.samuraiprogrammer.com/blog/content/binary/WindowsLiveWriter/OpenXMLRefreshafieldwhenthedocumentisope_10A90/image_thumb_1.png" width="392" height="136" /&gt;&lt;/a&gt; In
that file are all of the document level settings for your docx.&amp;#160; &lt;a href="http://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.settings.aspx" target="_blank"&gt;There’s
some really great stuff in here&lt;/a&gt;.&amp;#160; 
&lt;/p&gt;
&lt;p&gt;
If you’d like to use the &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=c6e744e5-36e9-45f5-8d8c-331df206e0d0&amp;amp;DisplayLang=en" target="_blank"&gt;OpenXML
SDK to set that value&lt;/a&gt; (and you’d be crazy not to), here’s some sample code:
&lt;/p&gt;
&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; font-size: 8pt; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; (WordprocessingDocument
document = WordprocessingDocument.Open(path, &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;))&lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
DocumentSettingsPart settingsPart = 
&lt;br /&gt;
document.MainDocumentPart.GetPartsOfType&amp;lt;DocumentSettingsPart&amp;gt;().First();&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;// Create object to update fields on open&lt;/span&gt;
&lt;br /&gt;
UpdateFieldsOnOpen updateFields = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; UpdateFieldsOnOpen();&lt;br /&gt;
updateFields.Val = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DocumentFormat.OpenXml.OnOffValue(&lt;span style="color: #0000ff"&gt;true&lt;/span&gt;);&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: #008000"&gt;// Insert object into settings part.&lt;/span&gt;
&lt;br /&gt;
settingsPart.Settings.PrependChild&amp;lt;UpdateFieldsOnOpen&amp;gt;(updateFields);&lt;br /&gt;
settingsPart.Settings.Save();&lt;br /&gt;
&lt;br /&gt;
}&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;h2&gt;w:dirty Attribute
&lt;/h2&gt;
&lt;p&gt;
This attribute is applied to the field you would like to have refreshed when the document
is opened in Word.&amp;#160; It tells Word to only refresh this field the next time the
document is opened.&amp;#160; For example, if you want to apply it to a field like your
table of contents, just find the w:fldChar and add that attribute:
&lt;/p&gt;
&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; font-size: 8pt; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;w:r&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;w:fldChar&lt;/span&gt; &lt;span style="color: #ff0000"&gt;w:fldCharType&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;begin&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;w:dirty&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;w:r&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
For a simple field, like the document author, you’ll want to add it to the w:fldSimple
element, like so:
&lt;/p&gt;
&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; font-size: 8pt; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;w:fldSimple&lt;/span&gt; &lt;span style="color: #ff0000"&gt;w:instr&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;AUTHOR
\* Upper \* MERGEFORMAT&amp;quot;&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #ff0000"&gt;w:dirty&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;w:r&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;br /&gt;
...&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;w:r&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;w:fldSimple&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;h2&gt;A caveat or two
&lt;/h2&gt;
&lt;p&gt;
&lt;strong&gt;Both of these methods will work just fine in Word 2010.&lt;/strong&gt;&amp;#160; 
&lt;/p&gt;
&lt;p&gt;
In Word 2007, though, you need to clear out the contents of the field before the user
opens the document.&amp;#160; For example, with a table of contents, Word will normally
cache the contents of the TOC in the fldChar element.&amp;#160; This is good, normally,
but here it causes a problem.&amp;#160; 
&lt;/p&gt;
&lt;p&gt;
For example, in a very simple test document, you would see the following cached data
(i.e.:&amp;#160; Heading 1, Heading 2, etc.):
&lt;/p&gt;
&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; font-size: 8pt; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;w:p&lt;/span&gt; &lt;span style="color: #ff0000"&gt;w:rsidR&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;00563999&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;w:rsidRDefault&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;00050B09&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;br /&gt;
...&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;w:r&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;w:fldChar&lt;/span&gt; &lt;span style="color: #ff0000"&gt;w:fldCharType&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;begin&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;w:r&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;w:r&lt;/span&gt; &lt;span style="color: #ff0000"&gt;w:rsidR&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;00563999&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;w:instrText&lt;/span&gt; &lt;span style="color: #ff0000"&gt;xml:space&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;preserve&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; TOC
\* MERGEFORMAT &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;w:instrText&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;w:r&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;w:p&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;w:p&lt;/span&gt; &lt;span style="color: #ff0000"&gt;w:rsidR&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;00F77370&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;w:rsidRDefault&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;00F77370&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;br /&gt;
...&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;w:r&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;br /&gt;
...&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;w:t&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;Heading
1&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;w:t&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;w:r&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;br /&gt;
...&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;w:p&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;w:p&lt;/span&gt; &lt;span style="color: #ff0000"&gt;w:rsidR&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;00F77370&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;w:rsidRDefault&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;00F77370&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;br /&gt;
...&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;w:r&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;br /&gt;
...&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;w:t&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;Heading
2&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;w:t&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;w:r&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;br /&gt;
...&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;w:p&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;w:p&lt;/span&gt; &lt;span style="color: #ff0000"&gt;w:rsidR&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;00F77370&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;w:rsidRDefault&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;00F77370&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;br /&gt;
...&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;w:r&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;w:rPr&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;w:noProof&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;w:rPr&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;w:fldChar&lt;/span&gt; &lt;span style="color: #ff0000"&gt;w:fldCharType&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;end&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;w:r&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;w:p&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
After you clear out the &lt;a href="http://www.urbandictionary.com/define.php?term=schmutz" target="_blank"&gt;schmutz&lt;/a&gt;,
you end up with just the begin element, the definition of the TOC and the end element:
&lt;/p&gt;
&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; font-size: 8pt; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;w:p&lt;/span&gt; &lt;span style="color: #ff0000"&gt;w:rsidR&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;00563999&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;w:rsidRDefault&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;00563999&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;br /&gt;
...&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;w:r&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;w:fldChar&lt;/span&gt; &lt;span style="color: #ff0000"&gt;w:fldCharType&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;begin&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;w:r&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;w:r&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;w:instrText&lt;/span&gt; &lt;span style="color: #ff0000"&gt;xml:space&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;preserve&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; TOC
\* MERGEFORMAT &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;w:instrText&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;w:r&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;w:p&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;w:p&lt;/span&gt; &lt;span style="color: #ff0000"&gt;w:rsidR&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;00B63C3C&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;w:rsidRDefault&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;00563999&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;w:rsidP&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;00B63C3C&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;w:r&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;w:fldChar&lt;/span&gt; &lt;span style="color: #ff0000"&gt;w:fldCharType&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;end&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;w:r&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;br /&gt;
...&lt;br /&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;w:p&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
Once you’ve made the updates, you can safely open up your file in Word 2007 and your
fields will update when the document opens.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blogs.msdn.com/b/brian_jones/" target="_blank"&gt;Big thanks for Zeyad
for his tip on trimming out the schmutz.&lt;/a&gt;
&lt;/p&gt;
&lt;h4&gt;Just to stress, this is improved in Word 2010 and you no longer need to clear
out the cached data in your fields.
&lt;/h4&gt;
&lt;p&gt;
Enjoy!
&lt;/p&gt;</description>
      <comments>http://www.samuraiprogrammer.com/blog/CommentView,guid,471f190b-cdf8-4695-b29d-684d3e55ce17.aspx</comments>
      <category>Development</category>
      <category>OpenXML</category>
    </item>
  </channel>
</rss>