VB error when I copy webite to server.

Posted on 2009-05-01
Last Modified: 2012-08-13
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, "", "", "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..
Question by:clynch302
    LVL 9

    Expert Comment


    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.


    Author Comment

    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, "", "", "Toner Order for xxxx, Location " + loc, sbMessage.ToString())
        End Sub

    Open in new window

    LVL 9

    Expert Comment

    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"



    Author Comment

    Nope. That doesnt seem to work.
    LVL 9

    Expert Comment

    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 project I can compile it without any problems...
    LVL 9

    Expert Comment

    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

    Accepted Solution

    Figured it out...

    Dim mailHelper As Object

    It worked
    LVL 9

    Expert Comment

    :=) great!

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Introduction While answering a recent question ( in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now