Introduction
In this blog, I will explain how I fixed the issue regarding Quick Parts. In this issue, the link broke between the document in the SharePoint library and the columns, which should appear as document property. This occurred while migrating content from on-premise SharePoint to SPO.
What is a Quick Part?
Quick Part is a feature in Microsoft Word which, among other things, allows you to insert a SharePoint Library Column as a field in the Document.
For example, the Created By and Modified By columns from the SharePoint library could be shown as data inside the document which could be handy for some use cases.
For a primer on Quick Parts, please visit this link https://support.office.com/en-us/article/use-quick-parts-and-autotext-in-word-7a527697-058f-4967-b8f1-aae0774e4813
Problem Statement
While this function has existed since Office 2010, I have never come across it being used until now.
We recently were in the process of migrating content from on-premise SharePoint to O365 SharePoint Online, when on a handful of sites, the owner reported a post-migration issue stating that some fields on the document were not updating when the metadata in the library was updated.
On analysis we found that Quick Parts had been used and we had to find a way to fix this.
In total we had around 5,000 documents across a handful of sites that were impacted by this.
Solution
What we first found was removing the existing quick part from the word document and adding it again manually fixed it.
However, as the document count was around 5,000, doing this manually was a lot of effort and we wanted to look at other options to see if there was a way this could be scripted.
In our specific case, the Quick Parts in the Word document were added in the Header and Footer Sections of the document and we found that we are able to access this section using C# and Office Word API.
So, here is what we did to script the solution:
a) Create a new word document on the O365 SPO library and create the header and footer section with the Quick Part. This will serve as the reference.
b) Open this reference document using C# code, access the header the footer and save it in a variable.
c) Connect to the library that was migrated to SPO, loop through all the documents one by one, remove the header and footer sections and replace them with the value in the variable created in "b)".
d) Save the document.
This, in a nutshell, did the trick for us.
The reference code to remove and add header or footer section in a document can be found here -
I hope this helps anyone else who faces a similar problem.
Reference Links -
https://social.msdn.microsoft.com/Forums/lync/en-US/48e63d00-3db8-4c1f-a018-d5169877da78/adding-quick-parts-programmatically-using-word-office-model?forum=worddev

srivatsa bsPosted Jun 7, 2024, 7:00 AM
Hi Skanda, can you share any sample code to implement this.
Hampus HellstromPosted Nov 27, 2020, 8:11 AM
Hello, We are trying to implement the same solution but keeps getting errors in the uploaded documents. Its says that the document is curropt. What can be the issue?