I am new to open xml sdk and i haven't much idea on how relationship work for wordprocessing document. I want to remove webtask-pane from my existing document which contains webtask-pane and its added through programmatically.
After deleting WebExtensionPart from WordprocessingDocument using open office xml.
Result : document get corrupted. Reason : Relationship part is exists after deleting WebExtensionPart.
Code :
public static void RemoveTaskPaneExt(WordprocessingDocument package)
{
WebExTaskpanesPart webExTaskpanesPart1 = package.GetPartsOfType<WebExTaskpanesPart>().FirstOrDefault();
if (webExTaskpanesPart1 != null)
{
WebExtensionPart aWebExtension =
webExTaskpanesPart1.GetPartsOfType<WebExtensionPart>()
.Where(
x =>
x.WebExtension.WebExtensionStoreReference.Id ==
System.Configuration.ConfigurationManager.AppSettings["PaneID"])
.FirstOrDefault();
if (aWebExtension != null)
{
bool result = package.WebExTaskpanesPart.DeletePart(aWebExtension);
}
}
}
Please help. Thanks in advance.
The following will remove all WebExtensionTaskpanes and your Word file will be valid. Call this instead of your method above.