Neodynamic Barcode Professional 3.0 (or greater) for ASP.NET (WebControl)
Microsoft .NET Framework 2.0 (or greater)
Microsoft Visual Studio 2005, Visual Web Developer Express Edition or Microsoft Expression Web
In the following Step-By-Step Guide we're going to create a simple ASP.NET web page which lets you to generate and send HTML emails featuring barcode images (some useful scenarios may involve any kind of barcode tickets, newsletters, invitations, and so on) created by Barcode Professional for ASP.NET and the System.Net.Mail classes.
Follow these steps:
Private Function GetBarcodeImage() As System.IO.MemoryStream
'Create an instance of BarcodeProfessional class
Dim bcp As New Neodynamic.WebControls.BarcodeProfessional.BarcodeProfessional()
'Set barcode settings...
'Code 128 symbology
bcp.Symbology = Neodynamic.WebControls.BarcodeProfessional.Symbology.Code128
'Set a fictitious value to encode
bcp.Code = Guid.NewGuid().ToString().Replace("-", "").Substring(0, 20).ToUpper()
'Return barcode stream
Return New System.IO.MemoryStream(bcp.GetBarcodeImage(System.Drawing.Imaging.ImageFormat.Png))
End Function
private System.IO.MemoryStream GetBarcodeImage()
{
//Create an instance of BarcodeProfessional class
Neodynamic.WebControls.BarcodeProfessional.BarcodeProfessional bcp = new Neodynamic.WebControls.BarcodeProfessional.BarcodeProfessional();
//Set barcode settings...
//Code 128 symbology
bcp.Symbology = Neodynamic.WebControls.BarcodeProfessional.Symbology.Code128;
//Set a fictitious value to encode
bcp.Code = Guid.NewGuid().ToString().Replace("-","").Substring(0,20).ToUpper();
//Return barcode stream
return new System.IO.MemoryStream(bcp.GetBarcodeImage(System.Drawing.Imaging.ImageFormat.Png));
}
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'Create the mail message
Dim mail As New System.Net.Mail.MailMessage()
'Set the email addresses
mail.From = New System.Net.Mail.MailAddress("me@mycompany.com")
mail.To.Add(Me.TextBox1.Text)
'Set the subject
mail.Subject = "John Doe in Concert - Barcode Ticket"
'Create the Html part.
'To embed the barcode image, we need to use the prefix cid in the img src attribute.
'The cid value will map to the Content-Id of a Linked resource.
'Example: will map to a LinkedResource with a ContentId of barcodeticket
Dim htmlContent1 As String = "NEOMIX ADMIT ONE NEO STADIUM GENERAL ADMISSION John Doe in Concert "
Dim htmlContent2 As String = ""
Dim htmlContent3 As String = " May
19
2007 SATURDAY
8:00 PM $ 98.00
"
Dim htmlView As System.Net.Mail.AlternateView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(htmlContent1 + htmlContent2 + htmlContent3, Nothing, "text/html")
'Create the LinkedResource (embedded barcode image)
Dim barcode As New System.Net.Mail.LinkedResource(Me.GetBarcodeImage(), "image/png")
barcode.ContentId = "barcodeticket"
'Add the LinkedResource to the view
htmlView.LinkedResources.Add(barcode)
'Add the view
mail.AlternateViews.Add(htmlView)
'specify the mail server address
Dim smtp As New System.Net.Mail.SmtpClient("127.0.0.1")
'send the message
smtp.Send(mail)
End Sub
protected void Button1_Click(object sender, EventArgs e)
{
//Create the mail message
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
//Set the email addresses
mail.From = new System.Net.Mail.MailAddress("me@mycompany.com");
mail.To.Add(this.TextBox1.Text);
//Set the subject
mail.Subject = "John Doe in Concert - Barcode Ticket";
//Create the Html part.
//To embed the barcode image, we need to use the prefix 'cid' in the img src attribute.
//The cid value will map to the Content-Id of a Linked resource.
//Example: will map to a LinkedResource with a ContentId of 'barcodeticket'
string htmlContent1 = "NEOMIX ADMIT ONE NEO STADIUM GENERAL ADMISSION John Doe in Concert ";
string htmlContent2 = "";
string htmlContent3 = " May
19
2007 SATURDAY
8:00 PM $ 98.00
";
System.Net.Mail.AlternateView htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(htmlContent1 + htmlContent2 + htmlContent3, null, "text/html");
//Create the LinkedResource (embedded barcode image)
System.Net.Mail.LinkedResource barcode = new System.Net.Mail.LinkedResource(this.GetBarcodeImage(), "image/png");
barcode.ContentId = "barcodeticket";
//Add the LinkedResource to the view
htmlView.LinkedResources.Add(barcode);
//Add the view
mail.AlternateViews.Add(htmlView);
//specify the mail server address
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("127.0.0.1");
//send the message
smtp.Send(mail);
}
We provide best-in-class customer service and support directly from members of our dev team! If we are available when you contact us, you will get a response in few minutes; otherwise the maximum turnaround is 24hs in most cases.