vmoss:
Hi thanks for the code snippet for the OpenXml sdk v2.0
I have an unanswered question I was wondering at the bottom of the code
where you have :
//Insert the altChunk tag just before content control
sdtBlock.InsertBeforeSelf(altChunk);
How can I just insert the altChunk at the bottom of the .docx or what is sdtBlock?
Here is how you can insert a file at the end of the document (after the last paragraph):
string document = @"D:\TestDoc.docx";
string indocument = @"D:\InDoc.docx";
using (WordprocessingDocument doc = WordprocessingDocument.Open(document, true))
{
//Get the last paragraph in the document
Paragraph paragraph = doc.MainDocumentPart.Document.Descendants<Paragraph>().Last();
//Create a new Alternative Format part
AlternativeFormatImportPart inDocPart = doc.MainDocumentPart.AddAlternativeFormatImportPart(AlternativeFormatImportPartType.WordprocessingML);
//Open file to be inserted and stream its contents into the part
using (FileStream stream = new FileStream(indocument, FileMode.Open))
{
inDocPart.FeedData(stream);
}
//Create a AltChunk - <w:altChunk> and give the reltionship if linking it to the
//alternative format part we added above
AltChunk altChunk = new AltChunk();
altChunk.Id = doc.MainDocumentPart.GetIdOfPart(inDocPart);
//Insert the altChunk tag after the paragraph
paragraph.InsertAfterSelf(altChunk);
//Save the document
doc.MainDocumentPart.Document.Save();
}