net library objects so far we have looked at the following objects in learning about asp.net:...
TRANSCRIPT
.NET Library ObjectsSo far we have looked at the following objects in
learning about ASP.NET:Controls
Used to control the screen / interface and gather input and display output.
VariablesUsed to control the computers RAM and allow it to
store data / perform calculations.Custom Objects
Used by programmers to perform specialised tasks.
The .NET LibraryThe .NET part of ASP.NET refers to a library of
objects that allow you the programmer to perform a huge range of tasks
System
Input-Output Provides tools for file input and output
DrawingProvides graphical drawing tools
WebProvides tools for Internet interconnectivity
DataProvides tools for accessing databases
We will look at two examples
The mail message objectUsed to create and send emails.
The SMTP client objectUsed to control a mail server.
The Mail Message ObjectIt may be found in the following part of
the .NET framework…
System.Net.Mail
To create a mail message object we would use the following line of code…
Dim myMessage As New System.Net.Mail.MailMessage(From, to, subject,body)
We would use the following line of code…Dim myMessage As New
System.Net.Mail.MailMessage(“[email protected]”,
“[email protected]”, “Hello John”,”Hi this is a test!”)
The SMTP Client ObjectA mail server is a specialised computer that
deals with the sending and receiving of email messages
DMU mail.cse.dmu.ac.ukVirgin smtp.ntlworld.co.ukOrange smtp.wannadoo.co.ukTiscali smtp.tiscali.co.uk
SMTP SMTP (Simple Mail Transfer Protocol) is the name of the software
that send emails.
It runs on a named machine so we need to know the name of the machine in order to send emails.
The SMTP client is stored in : System.Net.Mail
So to create a new SMTP client object we would use the following code...
Dim Server As New System.Net.Mail.SmtpClient("name of server")
E.g.
Dim Server As New System.Net.Mail.SmtpClient("mail.cse.dmu.ac.uk")
Sending the Mail MessageDim myMessage As New System.Net.Mail.MailMessage
(“[email protected]”, “[email protected]”, “Hello John”,”Hi this is a test!”)
Dim Server As New System.Net.Mail.SmtpClient("mail.cse.dmu.ac.uk")
Server.Send(myMessage)
Working ExampleTo see all of this working we shall look at the
code for the resend password page “resend.aspx”
What is an Object Again?“An object is a way of representing
computer technology in such a way so that we may send it instructions and
data.”
Creating an email and controlling a mail server are quite complex tasks, however “wrapping up” the complexity in objects means that we can perform this whole process in three lines of code.
Questions2. Write down as many uses you can think of on the web
for an email object 3. The following is the declaration for another .NET
library object: Dim MyFile As New
System.IO.StreamReader("myfile.txt") This object is used to read data from a file stored on the
hard disk, in this case “myfile.txt”