Convert C# into VB.Net

Posted on 2007-10-12
Last Modified: 2013-11-26
Hello Everyone,

How can I convert this code into

<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="ASPEMAILLib" %>
<%@ Import Namespace="System.Reflection" %>

<script runat="server" LANGUAGE="C#">

void Page_Load(Object Source, EventArgs E)
      // Change this to your own SMTP server
      String strHost = "";      
      txtHost.InnerHtml = strHost;      
      if( IsPostBack )
            // MailSender object declaration
            ASPEMAILLib.IMailSender objMail;
            objMail = new ASPEMAILLib.MailSender();

            objMail.Host = strHost;

            objMail.From = txtFrom.Value;            // From address
            objMail.FromName = txtFromName.Value;      // optional

            // To address, 2nd argument optional
            objMail.AddAddress(txtTo.Value, Missing.Value);            
            // message subject
            objMail.Subject = txtSubject.Value;
            // message body
            objMail.Body = txtBody.Value;

                  txtMsg.InnerHtml = "<font color=green>Success! Message sent to " + txtTo.Value + ".</font>";
            catch(Exception e)
                  txtMsg.InnerHtml = "<font color=red>Error occurred: " + e.Message + "</font>";

Question by:sonu19
    LVL 27

    Accepted Solution

    Here you go:

    <%@ Imports Namespace="System.Web" %>
    <%@ Imports Namespace="ASPEMAILLib" %>
    <%@ Imports Namespace="System.Reflection" %>

    <script runat="server" LANGUAGE="VB">

    Public Sub Page_Load(ByVal Source As Object, ByVal E As EventArgs)

          'Change this to your own SMTP server
          Dim strHost As String = ""
          txtHost.InnerHtml = strHost
          if IsPostBack = True Then

                'MailSender object declaration
                Dim objMail as ASPEMAILLib.IMailSender
                objMail = new ASPEMAILLib.MailSender()

                objMail.Host = strHost

                objMail.From = txtFrom.Value           'From address
                objMail.FromName = txtFromName.Value   ' optional

                'To address, 2nd argument optional
                objMail.AddAddress(txtTo.Value, Missing.Value)
                'message subject
                objMail.Subject = txtSubject.Value
                'message body
                objMail.Body = txtBody.Value

                      txtMsg.InnerHtml = "<font color=green>Success! Message sent to " & txtTo.Value & ".</font>"

                catch e As Exception
                      txtMsg.InnerHtml = "<font color=red>Error occurred: " & e.Message & "</font>"
              end try
          End If
    End Sub


    LVL 46

    Expert Comment

    by:Wayne Taylor (webtubbs)

     Imports System.Web
     Imports ASPEMAILLib
     Imports System.Reflection

     Private Sub Page_Load(ByVal Source As Object, ByVal E As EventArgs)
         ' Change this to your own SMTP server
         Dim strHost As String = ""
         txtHost.InnerHtml = strHost
         If IsPostBack Then
             ' MailSender object declaration
             Dim objMail As ASPEMAILLib.IMailSender
             objMail = New ASPEMAILLib.MailSender()
             objMail.Host = strHost
             objMail.From = txtFrom.Value
             ' From address
             objMail.FromName = txtFromName.Value
             ' optional
             ' To address, 2nd argument optional
             objMail.AddAddress(txtTo.Value, Missing.Value)
             ' message subject
             objMail.Subject = txtSubject.Value
             ' message body
             objMail.Body = txtBody.Value
                 txtMsg.InnerHtml = "<font color=green>Success! Message sent to " + txtTo.Value + ".</font>"
             Catch e As Exception
                 txtMsg.InnerHtml = "<font color=red>Error occurred: " + e.Message + "</font>"
             End Try
         End If
     End Sub

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
    A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
    This video discusses moving either the default database or any database to a new volume.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    779 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

    11 Experts available now in Live!

    Get 1:1 Help Now