Openxml SDK
fatima zaka
0
Reputation points
Hey, I am trying to remove an imbedded ole object in my word document through open xml sdk, but my file is corrupted after code execution. I am using the following code to iterative remove ole objects in my word file:
WordprocessingDocument doc = WordprocessingDocument.Open(inputFilePath, true);
{
MainDocumentPart mainPart = doc.MainDocumentPart;
// Iterate through the parts and remove embedded objects
if (mainPart.Document.Body.Descendants<DocumentFormat.OpenXml.Vml.Office.OleObject>().Any())
{
foreach (var oleObj in mainPart.Document.Body.Descendants<DocumentFormat.OpenXml.Vml.Office.OleObject>())
{
oleObj.Remove();
}
//Delete the embedded objects. This will remove the actual attached files from the document.
mainPart.DeleteParts(mainPart.EmbeddedObjectParts);
//Delete all picture in the document
mainPart.DeleteParts(mainPart.ImageParts);
}
Community Center Not monitored
46,173 questions
Sign in to answer