ASP.NET (35) SQL (25) JAVASCRIPT (24) HTML (14) STYLE SHEET (6) ASP (4) SCRIPT (1)

Search me out HERE!!

Fill DATASET from Cache in ASP.net

Below code will show how to fill DataSet from cache instead of getting data each time from Database:


public DataSet load_data()
    {
        DataSet ds;
        if (Cache["test"] == null)
        {
            SqlConnection cn = new SqlConnection("server=.;database=pubs;uid=sa;password=;");
            cn.Open();
            SqlDataAdapter cmd = new SqlDataAdapter("select * from test",cn);
            ds = new DataSet();
            cmd.Fill(ds, "test");
            Cache.Insert("test", ds, null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(5));
            cn.Close();
        }
        else
        {
            ds = (DataSet)Cache["test"];
        }
        return ds;
    }

You can get your Dataset by just calling load_data() method as given below:
DataSet ds = load_data();

Add to BOOK MARK using Javascript

Below JavaScript can be used to set Book Mark link

JAVASCRIPT:
<script type="text/javascript">
function bookmarksite(title,url){
if (window.sidebar) // firefox
    window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
    var elem = document.createElement('a');
    elem.setAttribute('href',url);
    elem.setAttribute('title',title);
    elem.setAttribute('rel','sidebar');
    elem.click();
}
else if(document.all)// ie
    window.external.AddFavorite(url, title);
}
</script>


HTML CODE:
<a href="javascript:bookmarksite('Google', 'http://www.google.com')"> Add to Favorites </a>

To Send Mail in ASP.NET With C# using GMAIL Account

Below code can be used in ASP.net with C# to send email using your Gmail Account.

string from = me@gmail.com; //Replace this with your own correct Gmail Address
string to = to@abc.com //Replace this with the Email Address to whom you want to send the mail

System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
mail.To.Add(to);
mail.From = new MailAddress(from, "Admin" , System.Text.Encoding.UTF8);
mail.Subject = "This is a test mail" ;
mail.SubjectEncoding = System.Text.Encoding.UTF8;
mail.Body = "This is Email Body Text";
mail.BodyEncoding = System.Text.Encoding.UTF8;
mail.IsBodyHtml = true ;
mail.Priority = MailPriority.High;

//Add the Creddentials- use your own email id and password
SmtpClient client = new SmtpClient();
client.Credentials = new System.Net.NetworkCredential(from, "Password");

client.Port = 587; // Gmail works on this port
client.Host = "smtp.gmail.com";
client.EnableSsl = true; //Gmail works on Server Secured Layer
try
{
    client.Send(mail);
}
catch (Exception ex)
{
    HttpContext.Current.Response.Write(ex2.ToString());
} // end try