I’m trying to produce mailing labels from a database that has both address1 and address2 fields. The problem I am having is that if address2 is NULL (verified from the data) then a blank line appears in the output document. This is the code we are using and any help would be greatly appreciated. Thanks! Bill
// Remove Empty Paragraphs
doc.MailMerge.RemoveEmptyParagraphs = true;
// Do the mail merge from the DataVeiew to the document
doc.MailMerge.Execute(dv.ToTable());
// Remove Next_Field when document from empty records
ArrayList list = new ArrayList();
NodeCollection collection = doc.GetChildNodes(NodeType.FieldStart, true);
foreach (FieldStart start in collection)
{
if (start.FieldType == FieldType.FieldNext || start.FieldType == FieldType.FieldMergeField)
{
list.Add(start);
}
}
foreach (Node start in list)
{
Node node = start;
while (node.NodeType != NodeType.FieldEnd)
{
node = node.NextSibling;
node.PreviousSibling.Remove();
}
node.Remove();
}
// Strip out merged fields with no data
int i;
string[] names = doc.MailMerge.GetFieldNames();
DocumentBuilder builder = new DocumentBuilder(doc);
for (i = 1; i < names.Length; i++)
{
builder.MoveToMergeField(names[i]);
}
// Save the mail merge document as Out.doc
doc.Save(MyPath + @"\Out.doc");
HttpContext.Current.Response.ContentType = "application/ms-word";
HttpContext.Current.Response.AddHeader("Content-Disposition", "inline;filename=Out.doc");
HttpContext.Current.Response.TransmitFile("Out.doc");