[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 358
  • Last Modified:

VB error when I copy webite to server.

Hello all,

I am working in Visual Web Developer 2008 Express and it builds and runs fine on my local machine. When i copy it over to the web server I get this error.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30451: Name 'MailHelper' is not declared.

Source Error:


Line 97:         sbMessage.Append("<br /><br />Comments: " + instruct)
Line 98:
Line 99:         MailHelper.SendMailMessage(name, "user@domain.com", "user@domain.com", "Toner Order for company, Location " + loc, sbMessage.ToString())
Line 100:
Line 101:    End Sub
I am not sure about declaring MailHelper and if so to what? I am using code from here..

  • 5
  • 3
1 Solution

The code you posted the webpage for declares MailHelper. Where did you put it and now? you need to add a new class to your project and then copy/paste that code from imports to end class into that.

clynch302Author Commented:
I have the MailHelper.vb in App_Code.
Imports System.Net.Mail
Imports Microsoft.VisualBasic
Imports MailHelper
Public Class MailHelper
    ''' <summary>
    ''' Sends an mail message
    ''' </summary>
    ''' <param name="from">Sender address</param>
    ''' <param name="recepient">Recepient address</param>
    ''' <param name="bcc">Bcc recepient</param>
    ''' <param name="cc">Cc recepient</param>
    ''' <param name="subject">Subject of mail message</param>
    ''' <param name="body">Body of mail message</param>
    Public Shared Sub SendMailMessage(ByVal from As String, ByVal cc As String, ByVal recepient As String, ByVal subject As String, ByVal body As String)
        ' Instantiate a new instance of MailMessage
        Dim mMailMessage As New MailMessage()
        Dim msg As New System.Net.Mail.MailMessage
        ' Set the sender address of the mail message
        mMailMessage.From = New MailAddress(from)
        ' Set the recepient address of the mail message
        mMailMessage.To.Add(New MailAddress(recepient))
        ' Check if the bcc value is null or an empty string
        'If Not bcc Is Nothing And bcc <> String.Empty Then
        ' Set the Bcc address of the mail message
        'mMailMessage.Bcc.Add(New MailAddress(bcc))
        'End If
        ' Check if the cc value is null or an empty value
        'If Not cc Is Nothing And cc <> String.Empty Then
        'Set the CC address of the mail message
        mMailMessage.CC.Add(New MailAddress(cc))
        'End If
        ' Set the subject of the mail message
        mMailMessage.Subject = subject
        ' Set the body of the mail message
        mMailMessage.Body = body
        ' Secify the format of the body as HTML
        mMailMessage.IsBodyHtml = True
        ' Set the priority of the mail message to normal
        mMailMessage.Priority = MailPriority.Normal
        ' Instantiate a new instance of SmtpClient
        Dim mSmtpClient As New SmtpClient()
        ' Send the mail message
    End Sub
End Class
And here is the ASPX.vb
Imports System.Net.Mail
Imports Microsoft.VisualBasic
Imports MailHelper
Partial Class _Default
    Inherits System.Web.UI.Page
    Protected Sub Email_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Email.TextChanged
    End Sub
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim name As String = Email.Text.Trim()
        Dim first As String = First_Name.Text.Trim()
        Dim last As String = Last_Name.Text.Trim()
        Dim addr As String = Address.Text.Trim()
        Dim cty As String = city.Text.Trim()
        Dim sta As String = state.Text.Trim()
        Dim zcode As String = zip.Text.Trim()
        Dim pnum As String = phone_number.Text.Trim()
        Dim instruct As String = message.Text.Trim()
        Dim loc As String = Location_Number.Text.Trim()
        'Line Item 1
        'Dim qty_1 As String = QTY1.Text.Trim()
        'Dim item_1 As String = item1.Text.Trim()
        'Dim model_1 As String = model1.Text.Trim()
        'Dim list_1 As String = List1.Text.Trim()
        Dim sbMessage As New StringBuilder()
        'Button1.Enabled = False
        sbMessage.Append("<style>td {background-color: #FFFFFF; padding-right: 5px;} tr {background-color: black;} table {background-color: yellow;}</style>")
        sbMessage.Append("<table><tr><td colspan=""4"">" + first + " " + last + " has submitted a toner order on: " + DateTime.Now + "</td></tr>")
        sbMessage.Append("<br /><br /><tr><td>Qty</td><td>Item</td><td>Printer Model</td><td>OEM/Remans</td></tr>")
        If QTY1.Text.Trim() <> "" Then
            sbMessage.Append("<tr><td>" + QTY1.Text.Trim() + "</td><td>" + item1.Text.Trim() + "</td><td>" + model1.Text.Trim() + "</td><td>" + List1.Text.Trim() + "</td></tr>")
        End If
        If QTY2.Text.Trim() <> "" Then
            sbMessage.Append("<tr><td>" + QTY2.Text.Trim() + "</td><td>" + item2.Text.Trim() + "</td><td>" + model2.Text.Trim() + "</td><td>" + List2.Text.Trim() + "</td></tr>")
        End If
        If QTY3.Text.Trim() <> "" Then
            sbMessage.Append("<tr><td>" + QTY3.Text.Trim() + "</td><td>" + item3.Text.Trim() + "</td><td>" + model3.Text.Trim() + "</td><td>" + List3.Text.Trim() + "</td></tr>")
        End If
        If QTY4.Text.Trim() <> "" Then
            sbMessage.Append("<tr><td>" + QTY4.Text.Trim() + "</td><td>" + item4.Text.Trim() + "</td><td>" + model4.Text.Trim() + "</td><td>" + List4.Text.Trim() + "</td></tr>")
        End If
        If QTY5.Text.Trim() <> "" Then
            sbMessage.Append("<tr><td>" + QTY5.Text.Trim() + "</td><td>" + item5.Text.Trim() + "</td><td>" + model5.Text.Trim() + "</td><td>" + List5.Text.Trim() + "</td></tr>")
        End If
        If QTY6.Text.Trim() <> "" Then
            sbMessage.Append("<tr><td>" + QTY6.Text.Trim() + "</td><td>" + item6.Text.Trim() + "</td><td>" + model6.Text.Trim() + "</td><td>" + List6.Text.Trim() + "</td></tr>")
        End If
        If QTY7.Text.Trim() <> "" Then
            sbMessage.Append("<tr><td>" + QTY7.Text.Trim() + "</td><td>" + item7.Text.Trim() + "</td><td>" + model7.Text.Trim() + "</td><td>" + List7.Text.Trim() + "</td></tr>")
        End If
        If QTY8.Text.Trim() <> "" Then
            sbMessage.Append("<tr><td>" + QTY8.Text.Trim() + "</td><td>" + item8.Text.Trim() + "</td><td>" + model8.Text.Trim() + "</td><td>" + List8.Text.Trim() + "</td></tr>")
        End If
        If QTY9.Text.Trim() <> "" Then
            sbMessage.Append("<tr><td>" + QTY9.Text.Trim() + "</td><td>" + item9.Text.Trim() + "</td><td>" + model9.Text.Trim() + "</td><td>" + List9.Text.Trim() + "</td></tr>")
        End If
        If QTY10.Text.Trim() <> "" Then
            sbMessage.Append("<tr><td>" + QTY10.Text.Trim() + "</td><td>" + item10.Text.Trim() + "</td><td>" + model10.Text.Trim() + "</td><td>" + List10.Text.Trim() + "</td></tr>")
        End If
        sbMessage.Append("</table><br /><br />Purchase Order Number: USA" + Format(Now, "MMddyyhhmmss") + "-" + loc)
        sbMessage.Append("<br /><br /><strong><u>Shipping/Billing Address:</u></strong>")
        sbMessage.Append("<br />" + first + " " + last)
        sbMessage.Append("<br />" + addr)
        sbMessage.Append("<br />" + cty)
        sbMessage.Append("<br />" + sta + "," + " " + zcode)
        sbMessage.Append("<br />" + pnum)
        sbMessage.Append("<br />" + name)
        sbMessage.Append("<br /><br />Comments: " + instruct)
        MailHelper.SendMailMessage(name, "xxxx@xxxx.com", "cxxxh@xxx.com", "Toner Order for xxxx, Location " + loc, sbMessage.ToString())
    End Sub

Open in new window

you could try to:

1. MailHelper.vb - delete "imports MailHelper"

2. in aspx.vb - replace "imports MailHelper" with "applicationname.MailHelper

applicationname = your application name, you'll see it from intellisense as an option. Eg. when creating a new project this would be "Imports WebApplication1.MailHelper"


Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

clynch302Author Commented:
Nope. That doesnt seem to work.
then I'm sorry, can't help. maybe it is because you try to call a public class/sub from a protected one, but I don't know how to do it. On the other side, when I put your code in a new asp.net project I can compile it without any problems...
Maybe it's something like

Friend WithEvents MailHelper As WebApplication4.MailHelper
Friend WithEvents SendMailMessage As MailHelper

in aspx.vb after the line "Inherits System.Web.UI.Page"

good luck
clynch302Author Commented:
Figured it out...

Dim mailHelper As Object

It worked
:=) great!

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now