Hi,
I got some code from you to remove all text frames from header or footers
But with Version 24.6, it get corrupted with following exception:
Aspose.Words.FileCorruptedException
HResult=0x80131500
Message=The document appears to be corrupted and cannot be loaded.
Source=Aspose.Words
StackTrace:
at Aspose.Words.Document.(Stream , LoadOptions )
at Aspose.Words.Document.(Stream , LoadOptions )
at Aspose.Words.Document..ctor(Stream stream, LoadOptions loadOptions)
at Aspose.Words.Document..ctor(Stream stream)
at Aspose.Form1.button1_Click(Object sender, EventArgs e) in C:\Users\D055940\source\repos\Aspose\Aspose\Form1.cs:line 50
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at Aspose.Program.Main() in C:\Users\D055940\source\repos\Aspose\Aspose\Program.cs:line 19
This exception was originally thrown at this call stack:
[External Code]
Inner Exception 1:
ArgumentException: Cannot insert a node of this type at this location.
Here is the code
Aspose.Words.License lic = new Aspose.Words.License();
lic.SetLicense("Aspose.Total.lic");
Document WordDoc = new Document("Relatorio_V1_crash.docx");
foreach (Paragraph p in WordDoc.GetChildNodes(NodeType.Paragraph, true))
{
// Check whter paragraph is in header/footer
if (p.GetAncestor(NodeType.HeaderFooter) != null)
{
// Check whether the paragraph is text frame.
if (p.FrameFormat.IsFrame)
{
p.Remove();
}
}
}
using (MemoryStream mem = new MemoryStream())
{
WordDoc.Save(mem, SaveFormat.Docx);
WordDoc = new Document(mem);
}
Relatorio_V1_crash.zip (1.0 MB)
Kind regards,
@Nachti