Print Mailing Labels from asp.net?

I’m converting an Access application to an asp.net web/SQL Server application. One of the current features of the Access app is printing mailing labels. Can this be done through the web using the Word component? I would assume if it can generate the document and send it to the user it shouldn’t be much different.

Hi,

Thank you for considering Aspose.

Creating mailing labels is one of the general Aspose.Word usage scenarios. Please take a look at the Mailing Labels demo either at our demo page or one that is included into the msi installer available for download at our download page.

Is it possible to allow the user to select a label or enevlope size and dynamically create the document for mail merge? Or would I need to create a template doc for each label size? Anyone do anything like this before?

You could do it dynamically, the component allows you to build Documents on the fly. However, depending on the number of label sizes you have it might just be simpler to create a template doc for each. Even quicker, if you’re purchasing your labels from some vendor then chances are they might already have a Word template available for each label size that you can download. It all depends on your need/time requirements.

I think I’m going to allow users to upload templates as needed although I’m still trying to figure out the easiest way to create them in word. A couple issues have come up in my testing though and I could not find much in the forums yet.

  1. When using FireFox it sees the document as an xml file and therefore does not default to Word as the application to open with. I had to save to the desktop and rename the file with .doc. I’m assuming this has something to do with mime-types but not sure if there’s an easy fix.
  2. I thought I came across a post on this but can’t find it now. When doing the mailmerge for labels and you have two address fields, Address1 and Address2, it would be nice if it didn’t leave a blank row for Address2 if it is empty. Is there any way to accomplish this? Thanks.

Concerning your second question, to achieve what you want just set

MailMerge.RemoveEmptyParagraphs = true;

before doing MailMerge.Execute.
As for the first question, please explain in details what are you doing and send me the problem document sample. I will check what could be done.

Ok, in the latest version of FireFox it tries to save the document as xml not as a doc. (See attached pic) It seems to work fine in IE though.
This is the code I’m using:

Aspose.Words.License wordsLicense = new Aspose.Words.License();
wordsLicense.SetLicense("Aspose.Custom.lic");
Document doc = new Document(System.IO.Path.Combine(Server.MapPath("~/Pub/LabelTemplates/"), ddlTemplate.SelectedValue));
DataTable dtContacts = GetData();
doc.MailMerge.RemoveEmptyParagraphs = true;
doc.MailMerge.Execute(dtContacts);
doc.MailMerge.DeleteFields();
doc.Save("MailMergeTest.doc", SaveFormat.FormatDocument, SaveType.OpenInWord, this.Response);

Have you tried to set MS Word as default editor to ‘open with’ in the dialog snapshot of which you have provided? Seems that Mozilla does not recognize word doc mime type (application/msword).

Ok, was able to remedy the issue by having Words save the file to a temp folder first and then creating a link to the file on the page.
On another issue though, it seems to be skipping some records when doing the mail merge. For example with one the data table had 5 records but it only filled in the top 3 labels. On another the data table contained 11 records and it only filled in the top 6 lables. Every label container in the doc has the NEXT modifier except the first. Any ideas.

Please send us your template document and I will check what could be done to remedy the problem.

Here is the template.

You have actually put two NEXT fields into each label except first - one in the beginning and one in the end. And you really need only one NEXT per label. So, remove the ending NEXTs and it will work fine after that.