using (MemoryStream destination = new MemoryStream()) { using (FileStream sourcefilecopy = File.Open(file, FileMode.Open)) { sourcefilecopy.CopyTo(destination); } using (WordprocessingDocument doc = WordprocessingDocument.Open(destination, true)) { var docPart = doc.MainDocumentPart; if(docPart.HeaderParts.Count() > 0 || docPart.FooterParts.Count() > 0) { docPart.DeleteParts(docPart.HeaderParts); docPart.DeleteParts(docPart.FooterParts); Document document = docPart.Document; var headers = document.Descendants<HeaderReference>().ToList(); foreach (var header in headers) { header.Remove(); } var footers = document.Descendants<FooterReference>().ToList(); foreach (var footer in footers) { footer.Remove(); } document.Save(); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)