You are here:ActiveXperts.com > SMS Component > How to Use the ActiveXperts SMS Component > GSM modem send > ASP.NET (Visual Basic)
The ActiveXperts SMS Component is a software development kit (SDK) to enhance an application or script with SMS or Pager functionality. SMS messages can be sent/received using a GSM modem, an SMPP provider or an HTTP compliant SMSC.
In this example we are going to use Visual Studio 2008 to create an ASP.NET Visual Basic project named 'DemoApp' in a solution named 'DemoSolution'. We are going tot store this project in the directory 'C:\MyProjects'. All of these names can be changed according to your preferences. This demo project will ask the user to give a phone number and a message body in the web interface.
You must install and configure Internet Information Services (IIS) before using the ActiveXperts SMS Component with ASP .NET
Download the the ActiveXperts SMS Component from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.
Launch Microsoft Visual Studio from the Start menu. Choose 'New' from the 'File' menu and click on 'Web Site'. In the 'Web Site' dialog, select ASP .NET Web Site. Select a name for the application and a name for the solution. Also, select the directory where you want to store the project:
Now that a new project has been created, you must add a reference to the ActiveXperts SMS Component in the project to be able to use the the ActiveXperts SMS Component objects. To do so, choose 'Add Reference...' from the 'Project' menu. In the 'Add Reference' dialog that pops up, select the 'COM' tab and select the 'ActiveXperts SMS Component Type Library' as shown in the following picture:
Click 'OK' to close the 'Add Reference' dialog.
The following code will show you how to declare and create the GSM and SMS objects. We will use the 'objGsm' object to send the message itself. The 'objSmsConstants' object containes constant values releated to the SMS objects.
Imports AxSms Imports System.IO Partial Public Class frmGsm Inherits System.Web.UI.Page Private objGsm As Gsm = New Gsm() Private objSmsConstants As Constants = New Constants() ... End Class
Below in the 'onClick' event of the send button we declare the 'objSmsMessage' object. The objSmsMessage object will be used to store information regarding the SMS message which will be sent.
... Dim objSmsMessage As Message objMessage = New Message ...
The following code will get the information you entered in the text fields, and store this information in the 'objMessage' object. If the multipart checkbox is selected, then the SMS message will be sent as a multipart message (multiple SMS's).
'Message Settings objMessage.Clear() objMessage.ToAddress = txtToAddress.Text objMessage.Body = txtBody.Text Dim iMultipart As Integer = objConstants.MULTIPART_OK objMessage.BodyFormat = objConstants.BODYFORMAT_TEXT If (cbxMultipart.Checked) Then iMultipart = objConstants.MULTIPART_OK Else iMultipart = objConstants.MULTIPART_TRUNCATE End If
The following code shows how to send an SMS message using the data that was stored in the 'objMessage' and 'objConstants' objects. The timeout value is set to 10 seconds, which means that the modem will try to send the message for 10 seconds, after this value it will stop trying.
' Send the message ! objGsm.SendSms(objMessage, iMultipart, 10000) strMessageReference = objMessage.Reference UpdateResult(objGsm.LastError) objGsm.Close()
You can download the full source code of this project from the ActiveXperts FTP site: ftp.activexperts-labs.com/samples/sms-component. There are many other working samples included with the product or on the FTP site.
The ActiveXperts SMS Component project ships with a set of Microsoft Visual Studio .NET samples. The projects are created with Microsoft Visual Studio 2008.
Users with a later version of Microsoft Visual Studio can open such a project. The Visual Studio Conversion Wizard will guide you through the process of converting the project to the version used.