Mamta Jain

Mamta Jain

  • NA
  • 417
  • 14.4k

how to remove header from word file by using DocumentFormat

Dec 11 2016 11:42 PM
How to remove header part from Selected word file using Document.Format 
I am using .Net Framework 2.0
 
My Code :
 
public void removeheader()
{
string temp_path = txtUpload.Text;
using (DocumentFormat.OpenXml.Packaging.WordprocessingDocument doc = WordprocessingDocument.Open(temp_path, true))
{
var docPart = doc.MainDocumentPart;
// if (docPart.HeaderParts.Count() > 0 )
{
docPart.DeleteParts(docPart.HeaderParts);
Document document = docPart.Document;
var headers = document.Descendants().ToList();
foreach (var header in headers)
{
header.Remove();
}
document.Save();
}
}
}.
 
 
Here DocumentFormat.OpenXml.Packaging.WordprocessingDocument doc = WordprocessingDocument.Open(temp_path, true)
getting Error , how I include related Framework SDK file to remove error ? or any other Suggestion 
 

Answers (5)