RSS

Monthly Archives: May 2012

Send email using ASP.NET

ASP.NET allows us to send email from the programming.

using System.Net.Mail;

The above namespace having the feature to send email. Include that namespace to coding.

public void SendEmail()

{

 SmtpClient smtp = new SmtpClient();

 MailMessage mail = new MailMessage();

 mail.To.Add(“ToMailID@mail.com”);

 mail.From = new MailAddress(“FromMailID@mail.com”);

 mail.Subject = “Subject Here”;

 mail.Body = “Message Here”;

 smtp.Host = “smtp.mail.com”;

 smtp.Credentials = new System.Net.NetworkCredential(“FromId@mail.com”,”Password”);

 smtp.EnableSsl = true;

 smtp.Send(mail);

}

By the above way we can send email..

Good Luck……………

 
Leave a comment

Posted by on May 29, 2012 in ASP.NET, C#.NET

 

Stored procedure in ASP.NET

First of all you create one procedure in sql.

Then by following code we’ll use the stored procedure in ASP.NET. The main advantage of using stored procedure in ASP.NET is that it is fast and we hide the SQL queries in programming.

SqlConnection con;

SqlCommand cmd = new SqlCommand();

con = new SqlConnection(“server=””;uid=sa;pwd=””;database=product”);

cmd = new SqlCommand(“Procedurename”, con);

cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.Add(“@name”, SqlDbType.VarChar).Value = TextBox1.Text; //1st parameter to proc

cmd.Parameters.Add(“@passwd”, SqlDbType.VarChar).Value =TextBox2.Text; //2nd parameter to proc

cmd.Parameters.Add(“@email”, SqlDbType.VarChar).Value = TextBox4.Text; //3rd parameter to proc

con.Open();

cmd.ExecuteNonQuery();

con.Close();

Best of luck………..

 
Leave a comment

Posted by on May 23, 2012 in ASP.NET, SQL

 

Read word by word from txt file in c#

The following is the c# code for reading the text file word by word.

        string a;
        string[] words = { “” };
        StreamReader Reader = new StreamReader(path);
        string[] s = File.ReadAllLines(path);
        while ((a = Reader.ReadLine()) != null)
        {
            words = a.Split(‘ ‘);
            foreach (string word in words)
                          Console.WriteLine(word);
        }

By this code, you can find the exact count of words, find exact certain length word(i.e. 5 letter word) and much more.

Good luck…………………………………..

 
Leave a comment

Posted by on May 19, 2012 in ASP.NET, C#.NET