Free Support Forum - aspose.com

Problem with moving sections

All,

I am trying to build an example of the moving sections between one document to another. I am defining an allDoc, which will hold the “sum” of 2 documents. When I get a new document, I check if allDoc has been assigned anything yet, If it has NOT, I set it to the current (first) document, if it is already assigned a document, I create new new doc called “doc” and move the sections from doc to allDoc. It runs fine, but when I save the document to disk and try to open it in Word, I get the message “There is not enough memory or diskspace to complete the operation”. Also, trying to send it to the browser just hangs the page for a while and eventually, I get memory error message too. The two individual documents open fine if I don’t do any section moving. I am including my code. Please let me know if anyone sees something wrong.

Thank you!!!

I have cut out some code to make it easier to review here…

private void Page_Load(object sender, System.EventArgs e) {

string templateFileName = “test.doc”;

Aspose.Word.Word wd2 = new Word();

string[] a = new string[2];
a[0] = “628”;
a[1] = “630”;
//a[2] = “629”;

Aspose.Word.Document allDoc = null;

Response.ContentType = “application/vnd.ms-word”;
Response.Charset = “”;


for (int i = 0; i < a.Length; i++){
string docID = aIdea;
// Code removed for easier reading, but I get the word data and put it into the byte array content

byte[] content = (byte[]) ds.Tables[0].Rows[0][DocumentAssemblyUtils.COL_CONTENT];

MemoryStream ms2 = new System.IO.MemoryStream();

ms2.Write(content,0,content.Length);

if (allDoc == null){
allDoc = new Document(ms2);
}else {
Aspose.Word.Document doc = new Document(ms2);
while (doc.Sections.Count > 0){
Section section = doc.Sections[0];
doc.Sections.RemoveAt(0);
allDoc.Sections.Add(section);
}


}

}

allDoc.Save(@“C:\tech\bmstest.doc”);
allDoc.Save(templateFileName, SaveFormat.FormatDocument, SaveType.OpenInBrowser, this.Response) ;
}

Please send the original documents to me to word@aspose.com.

The documents you’ve sent me combine just fine in my test. Both doc1 into doc2 and vice versa. Try using latest Aspose.Word hotfix. If there is still a problem, you must be doing something else in the code that I did not pick up.

[Test]

public void TestBradCombineDocs()

{

TestUtil.SetUnlimitedLicense();

Document srcDoc = TestUtil.Open(@“Other\BradCombineDocs\doc2.doc”);

Document dstDoc = TestUtil.Open(@“Other\BradCombineDocs\doc1.doc”);

while (srcDoc.Sections.Count > 0)

{

Section section = srcDoc.Sections[0];

srcDoc.Sections.RemoveAt(0);

dstDoc.Sections.Add(section);

}

TestUtil.Save(dstDoc, @“Other\BradCombineDocs\doc Out.doc”);

}

I now get this error when updating from Word 2.4 to 3.0.2 when the Sections.Add portion of the code runs.

while (LetterWord.Sections.Count > 0)
{
Aspose.Word.Section LetterSection = LetterWord.Sections[0];
LetterWord.Sections.RemoveAt(0);
WordMain.Sections.Add(LetterSection);

}

The newChild was created from a different document than the one that created this node.

Nevermind I read the upgrade information.

The newChild was created from a different document than the one that created this node.

Line 998: Section section = doc1.Sections[0];
Line 999: doc1.Sections.RemoveAt(0);
Line 1000: doc2.Sections.Add(section);

I am now getting this error as well. Can someone please point me to the upgrade information or the fix this solves this?

Hi,

Thank you for considering Aspose.

After Aspose.Word v3.0 is out, the way of moving sections changed, please read here:

http://www.aspose.com/Wiki/default.aspx/Aspose.Word/V3Migration.html