internal void DeleteHeadersOrFooters(bool b)
{
string reference = "footer";
if (b)
reference = "header";
// Get all header Relationships in this document.
var header_relationships = mainPart.GetRelationshipsByType(string.Format("http://schemas.openxmlformats.org/officeDocument/2006/relationships/{0}", reference));
foreach (PackageRelationship header_relationship in header_relationships)
{
// Get the TargetUri for this Part.
Uri header_uri = header_relationship.TargetUri;
// Check to see if the document actually contains the Part.
if (!header_uri.OriginalString.StartsWith("/word/"))
header_uri = new Uri("/word/" + header_uri.OriginalString, UriKind.Relative);
if (package.PartExists(header_uri))
{
// Delete the Part
package.DeletePart(header_uri);
// Get all references to this Relationship in the document.
var query =
(
from e in mainDoc.Descendants(XName.Get("body", w.NamespaceName)).Descendants()
where (e.Name.LocalName == string.Format("{0}Reference", reference)) && (e.Attribute(r + "id").Value == header_relationship.Id)
select e
);
// Remove all references to this Relationship in the document.
for (int i = 0; i < query.Count(); i++)
query.ElementAt(i).Remove();
// Delete the Relationship.
package.DeleteRelationship(header_relationship.Id);
}
}
}