My code: (c#)
string dataDir = @"C:\Users\leah_b\Documents\";
string fileName = "TryingAspose.docx";
Aspose.Words.Document doc = new Aspose.Words.Document(dataDir + fileName);
Aspose.Words.Document subDoc = new Aspose.Words.Document();
var allpara = doc.FirstSection.Body.GetChildNodes(NodeType.Paragraph, true);
for (int i = 0; i < allpara.Count; i++)
{
if (((Paragraph)allpara[i]).ParagraphFormat.OutlineLevel == OutlineLevel.Level1)
{
subDoc.Save(@"C:\Users\leah_b\Documents\a\" + i + ".docx");
subDoc.RemoveAllChildren();
subDoc.AppendChild(subDoc.ImportNode(allpara[i], true, ImportFormatMode.KeepSourceFormatting));
}
else
{
subDoc.AppendChild(subDoc.ImportNode(allpara[i], true, ImportFormatMode.KeepSourceFormatting));
}
}
returns error: cannot insert a node of this type at this location