.: Easy Soft Technologies :.

May 14, 2008

How To Send Email Message In .NET

Last day i see some question in one best forum for programming that want to know how to send an email using .NET.
I have some experience when i work in one dutch project (’ TennisSite ‘) by Wellfound and have a module for send an email for customer.

So i will explain it here, about how to send an email using .NET. We use System.Net.Mail namespace for this project.

Ok this is the code snippet for send an email using .NET

Dim strUserName As String = "" ‘Username for smtpclient
Dim strPassword As String = "" ‘user password for smtpclient
Dim strHostName As String = "" ’smtpaddress
Dim intPort As Integer = 25
Dim credentials As New System.Net.NetworkCredential(strUserName, strPassword)
Dim message As New MailMessage()
Dim emailClient As New SmtpClient(strHostName, intPort)

With message
       .From = New MailAddress(strUserName)
       .To.Add(txtSendTo.Text.Trim)
       .Subject = "Test Send Email"
       .Body = txtMessage.Text.Trim
       .IsBodyHtml = True
       .Attachments.Add(New Attachment("path of file")
       .Bcc.Add("email address")
       .CC.Add("email address")
End With

emailClient.Credentials = credentials

Try
        emailClient.Send(message)
Catch ex As Exception
        MsgBox(ex.Source & " : " & ex.Message, MsgBoxStyle.Exclamation, "Error Message")
Finally
        message = Nothing
        emailClient = Nothing
End Try

I hope this article will help you in your some application project for send an email in future.

Simple Application Using .NET Part I

On this article, i will share my knowladge about how to make a simple application "CRUD" (Create, Read, Update, Delete) in .NET. One days ago, i get a request from some one that want to learn about .NET application using ADO.NET

For this part i give a simple application that using MS Access as a database application. We using System.Data.OleDb namespace for this.

This is the code snippet for this simple application:

Try
    Using Conn As New OleDbConnection(connString)
            Conn.Open()
            Using sqlCommand As New OleDbCommand()
             With sqlCommand
                   .CommandType = CommandType.Text
                   .CommandText = _stringSQL
                   .Connection = Conn
                   .ExecuteNonQuery()
             End With
            End Using
    End Using
    Return True
Catch ex As Exception
    MsgBox(ex.Source & " : " & ex.Message, MsgBoxStyle.Exclamation, "Error Messages")
    Return False
End Try

This metode we use for execute the sql command that given in INSERT, UPDATE and DELETE command.
Then when we want to bind database field or READ from database, we use OleDbDataAdapter and fill it to DataTable

Try
     Using Conn As New OleDbConnection(connString)
             Using daResult As New OleDbDataAdapter(_stringSQL, Conn)
                     daResult.Fill(_dtResult)
             End Using
     End Using
Catch ex As Exception
     MsgBox(ex.Source & " : " & ex.Message, MsgBoxStyle.Exclamation, "Error Messages")
End Try

For detail you can download SimpleApplication source to learn more from there.
I hope this article can help everyone who want to learn .NET espesially in database application.

March 12, 2008

How to Upload File using FTP in ASP.Net 2.0

Filed under: Programming

In this article I will try to explain you the technique of uploading file using ASP.Net 2.0.

.Net Framework 2.0 came with many new features which helps the developers in solving daily routines problems/quires while developing an application either windows or desktop. Today as we have seen Web Application became the part of our life. When we are facing any difficulty regarding development we took help from web application, similarly, when we want to purchase any thing we look for e-commerce websites.

Since we are a part of 21st century and in this century we have seen many developments in technology. Technology facilitates users in many ways for example, remote universities. Student sitting on one end and university on the other, to transfer course content, lectures etc. usually FTP (File Transfer Protocol) is used. When we talk about .Net Framework 1.0 we didn’t see any facility in using FT Protocol. .Net Framework 2.0 provides us FTPWebRequest and FTPWebResponse classes. These two classes provide complete ease to developers to implement an entire FTP client right from their web application. To get more understanding about these classes consider an example that upload file from local system to ftp://localhost/. You can also transfer file to live servers by providing network credentials (UserID, PWD).

Create a public function named as uploadFileUsingFTP(). This fuction uses four parameters, CompleteFTPPath this parameter is used for passing URL of FTP, CompleteLocalPath used to receive local path. Third and Fourth parameters are UName and PWD used to validate network crediential. Code for this function is as follows:

Public Sub uploadFileUsingFTP(ByVal fileFTP As String, ByVal clientPath As String)
        Dim fileInf As FileInfo = New FileInfo(clientPath)

        ’Create a FTP Request Object and Specfiy a Complete Path and save your ftp addres
        ’User Name PWD of ftp in web config
        Dim CompleteFTPPath As String = ConfigurationManager.AppSettings("FTP") & fileFTP

        ‘If you want to access Resourse Protected You need to give User Name and PWD
        Dim UName As String = ConfigurationManager.AppSettings("UserFTP")
        Dim PWD As String = ConfigurationManager.AppSettings("PwdFTP")

        ‘Create FtpWebRequest object from Uri provided
        Dim ftp As System.Net.FtpWebRequest = CType(FtpWebRequest.Create(New Uri(CompleteFTPPath)), FtpWebRequest)

        ‘Provide the WebPermission Credintials
        ftp.Credentials = New System.Net.NetworkCredential(UName, PWD)

        ‘By default KeepAlive is true
        ftp.KeepAlive = False

        ‘Specify the command to be executed
        ftp.Method = System.Net.WebRequestMethods.Ftp.UploadFile

        ‘Specify the data transfer type
        ftp.UseBinary = True

        ‘Notify the server about the size of the uploaded file
        ftp.ContentLength = fileInf.Length

        ‘Set buffer size = 2 kb
        Dim buffLength As Integer = 2048
        Dim buff(buffLength) As Byte
        Dim contentLength As Integer

        ‘Open a file stream to read the file to be uploaded
        Dim fs As FileStream = fileInf.OpenRead()

        Try
            ‘Stream to which the file to be upload is written
            Dim strm As Stream = ftp.GetRequestStream()

            ‘Read from the file stream 2kb at a time
            contentLength = fs.Read(buff, 0, buffLength)

            ‘Till Stream content ends
            While contentLength 0
                ‘Write Content from the file stream to the FTP Upload Stream
                strm.Write(buff, 0, contentLength)
                contentLength = fs.Read(buff, 0, buffLength)
            End While

            ‘Close the file stream and the Request Stream
            strm.Close()
            fs.Close()
        Catch ex As Exception
            ‘Set error handling here
       End Try
End Sub

I hope this article will be help you when you get a problem how to use the FTP in ASP.NET. Good luck for you, and thanks.

March 4, 2008

Good Bye For Netscape

Filed under: Software, Technologies

DetikNet, Tuesday (04/03/2008)

The old web browser, Netscape Navigator, has gone. This American Online (AOL) web browser will not be operating again after 1 March 2008.

This news is not an issue. This situation looks when there is a recommendation for the user to change their browser to Firefox or Flock, that same technology with Netscape Navigator.

If we see in around 1990, Netscape has been having 90 % users who build by Marc Andreessen in 1994. In this era, Netscape play the important action in internet.

Information from BBC, Tuesday (4/3/2008), Netscape Navigator will get their stopping with happen by there is more popular browser now, such as Firefox and Internet Explorer (IE) that have 80 % user. Firefox is first rival of IE make a sensation with their action with make their customer increase every time. Otherwise Flock will be the social web browser in implement web 2.0

The Netscape’s said their disappointment about their web browser. They said that they do not want to change to using Flock or Firefox. And they hope sometimes Netscape will be growing up again.

Good Bye Netscape….

February 26, 2008

How To Embed The Video In ASP.NET

Filed under: Programming

So many website now, that give us the streaming video. But we never know how to make like that. Now i will make it simple. Just copy the code below and you can get your video in your website.
To begin with this application create new website in VS2005. Add two controls one is label control and other is button control. Your .aspx source view page looks like this:

<object id="wmplayer" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" type="application/x-object" width=400 height=400>
    <param name="AutoStart" value="true"/>
    <param name="URL" value=" videolocation "/>
    <param name="ShowStatusBar" value="0"/>
    <param name="ShowControls" value="0"/>
    <param name="uiMode" value="full"/>
    <param name="DisplaySize" value="4"/>
    <param name="ShowCaptioning" value="0"/>
    <embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/ Products/MediaPlayer/" SRC="mms://www.timmerwinkel.nl/winkel/video/512.asf" name="WMPlayer" ShowControls="0" ShowDisplay="0" ShowStatusBar="0"
width=400 height=400 />
<object/>

Just implement it and change the video location with your video location. I hope it can help you to embed your video in your website. Good luck and thanks.

Get free blog up and running in minutes with Blogsome
Theme designed by Jay of onefinejay.com