Problems when Removing Paragraphs from a word document


#1

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:

Line 70:         }
Line 71: 
Line 72:         WordDoc.Save(Request.PhysicalApplicationPath + "temp\\" + string.Format("TestSaving{0}.doc", argTagId));
Line 73:     }
Line 74: 

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(TempNCIdea [I].IsComposite.ToString() + "
");

TempNCIdea [I].Remove();

}

for (int i = 0; i <= myDocPara[SearchIndex].BeginIndex; i++)

{

TempNC[0].Remove();

}

for (int i = TempNC.Count - 1; i >= 0; i--)

{

if ((TempNCIdea [I].GetText().IndexOf("<#Begin") >= 0) || (TempNCIdea [I].GetText().IndexOf("<#End") >= 0))

{

TempNCIdea [I].Remove();

}

}

WordDoc.Save(Request.PhysicalApplicationPath + "temp\\" + string.Format("TestSaving{0}.doc", argTagId));

}


#2

Please send us the document and part of your code sufficient to reproduce the error.