Hi,
I am in the midst of evaluating aspose for my customer and encountered certain problems. I wrote a simple TestSaveDoc to remove certain paragraphs from a document and save it as another document and I encountered save error:
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
|
The codes work well if the document consist of only texts without images and tables. Can anyone help? The code snippets are as follows:
private void TestSaveDoc(int argTagId)
{
Document WordDoc = new Document(Request.PhysicalApplicationPath + "temp\\" + "SampleTagging.doc");
NodeCollection TempNC = WordDoc.GetChildNodes(NodeType.Paragraph, true);
int SearchIndex = myDocPara.FindItem(argTagId);
for (int i = TempNC.Count - 1; i >= myDocPara[SearchIndex].EndIndex; i--)
{
Response.Write(TempNC.IsComposite.ToString() + "
");TempNC.Remove();
}
for (int i = 0; i <= myDocPara[SearchIndex].BeginIndex; i++)
{
TempNC[0].Remove();
}
for (int i = TempNC.Count - 1; i >= 0; i--)
{
if ((TempNC.GetText().IndexOf("<#Begin") >= 0) || (TempNC.GetText().IndexOf("<#End") >= 0))
{
TempNC.Remove();
}
}
WordDoc.Save(Request.PhysicalApplicationPath + "temp\\" + string.Format("TestSaving{0}.doc", argTagId));
}