Monday, October 24, 2011

Beautiful introduction for HTML5

A very beautiful introduction on HTML5 new input tags

http://www.bipinjoshi.net/articles/e421a206-cb68-428b-939b-9e42a2feeec3.aspx

Friday, October 21, 2011

Send email using asp

Create an aspx page and Paste this code on the page and change the required credential on the page..


<%@ Language=VBScript %>
<% Option Explicit %>

<%

Dim strFrom
Dim strPassword
Dim strTo
Dim strSubject
Dim strRedirect
Dim strBody
Dim Field
Dim strSubmit
Dim strServer
Dim strThankyou

'=======================================
'---------------------------------------
'        Inside HTML File IMPUT
'---------------------------------------
'<form name = "mail" action="mail.asp" method="POST">
'---------------------------------------
'=======================================
'---------------------------------------
'        Information to Edit
'---------------------------------------
strFrom = "email@domain.com"
strTo = "email@domain.com"
'strTo = "email@domain.com"
strServer = "mail.domain.com"
strThankyou = "thankyou.htm"
'---------------------------------------
' POP/SMTP Password
'---------------------------------------
strPassword = "******"
'=======================================

'strSubject = Request("Subject")
'strSubject = Request("Title of the Paper Presentation")
strRedirect = Request("Redirect")

If Request.QueryString <> "" Then

    'For Each Field in Request.QueryString
        If LCase(Field) <> "Email" And LCase(Field) <> "to" And _
        LCase(Field)<> "subject" And LCase(Field) <> "redirect" And _
        Lcase(Field)<> "submit" Then
            'strBody = strBody & Field & ": " & Request(Field) & chr(13)+ chr(10)
            strbody=strbody&"Name                            :"&Trim(Request("firstname"))&"  "&chr(13)+chr(10)
            strbody=strbody&"Address                    :"&Trim(Request("address"))&"  "&chr(13)+chr(10)
            strbody=strbody&"E-mail                           :"&Trim(Request("email"))&"  "&chr(13)+chr(10)
            strbody=strbody&"Mobile No           :"&Trim(Request("phone"))&"  "&chr(13)+chr(10)
            strbody=strbody&"Zip / Pin code :"&Trim(Request("zip"))&"  "&chr(13)+chr(10)
            strbody=strbody&"Feedback             :"&Trim(Request("feedback"))&"  "&chr(13)+chr(10)
           
        End If
    'Next
   
Else
   

    'For Each Field in Request.Form
       
        If LCase(Field) <> "Email" And LCase(Field) <> "to" And _
        LCase(Field)<> "subject" And LCase(Field) <> "redirect" And _
        Lcase(Field)<> "submit" Then
            'strBody = strBody & Field & ": " & Request(Field) & chr(13)+ chr(10)
            strbody=strbody&"Name                            :"&Trim(Request("firstname"))&"  "&chr(13)+chr(10)
            strbody=strbody&"Address                    :"&Trim(Request("address"))&"  "&chr(13)+chr(10)
            strbody=strbody&"E-mail                           :"&Trim(Request("email"))&"  "&chr(13)+chr(10)
            strbody=strbody&"Mobile No           :"&Trim(Request("phone"))&"  "&chr(13)+chr(10)
            strbody=strbody&"Zip / Pin code  :"&Trim(Request("zip"))&"  "&chr(13)+chr(10)
            strbody=strbody&"Feedback             :"&Trim(Request("feedback"))&"  "&chr(13)+chr(10)
           
           
        End If
       
    'Next


End If

SendMail strFrom,strTo,strSubject,strBody,strServer,strThankyou,strPassword

%>


<%

Sub SendMail(strFrom,strTo,strSubject,strBody,strServer,strThankyou,strPassword)

On Error Resume Next

Dim Mailer
Set Mailer = server.createobject("CDO.Message")

Mailer.From = strFrom
Mailer.To = strTo
Mailer.TextBody = strBody
Mailer.Subject = "Contact Information"
'Mailer.Subject = request("sub")
With Mailer.Configuration
.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strServer
.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
'------------------------------------------------------------------------------
' For SMTP Authentication Modify ('.Fields) to (.Fields) for three fields Below
'------------------------------------------------------------------------------
'.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
'.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = strFrom
'.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = strPassword
'------------------------------------------------------------------------------
.Fields.Update
End With

Mailer.Send
Set Mailer = Nothing

If Err.number<>0 Then
    Response.Write Err.Description
    Response.End
End If

Response.Redirect str Thankyou

End Sub

%>

Wednesday, January 19, 2011

How to upload sql file to remote server using .aspx page

 Use this code carefully
just copy and paste the Code :



<%
    // Sample code for executing a T-SQL file using an ASP.NET page
    // Copyright (C) Microsoft Corporation, 2007.  All rights reserved.
   
    // Written as a sample with use in conjuction with the SQL Server Database Publishing Wizard
    // For more information visit http://www.codeplex.com/sqlhost/
   
    // **************************************************************************
    // Note: Please ensure that you delete this page once your database has been published to the remote server
    // **************************************************************************
     
     %>

<%@ Page Language="C#" AutoEventWireup="true"  %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Net" %>


<%
    // **************************************************************************
    // Update these variables here
    // **************************************************************************
   
    // Url of the T-SQL file you want to run
    string fileUrl = @"http://localhost:49286/Test/changes.sql";    //// change file path to this position
   
    // Connection string to the server you want to execute against
    string connectionString = @"Data Source=servername;Initial Catalog=databasename;Integrated Security=True;";
   
    // Timeout of batches (in seconds)
    int timeout = 600;


 %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Executing T-SQL</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
    </div>
    </form>
    <%
        SqlConnection conn = null;                  
        try
        {
            this.Response.Write(String.Format("Opening url {0}<BR>", fileUrl));
           
            // read file
            WebRequest request = WebRequest.Create(fileUrl);
            using (StreamReader sr = new StreamReader(request.GetResponse().GetResponseStream()))
            {
                this.Response.Write("Connecting to SQL Server database...<BR>");
               
                // Create new connection to database
                conn = new SqlConnection(connectionString);              
               
                conn.Open();

                while (!sr.EndOfStream)
                {
                    StringBuilder sb = new StringBuilder();
                    SqlCommand cmd = conn.CreateCommand();
                   
                    while (!sr.EndOfStream)
                    {
                        string s = sr.ReadLine();
                        if (s != null && s.ToUpper().Trim().Equals("GO"))
                        {
                            break;
                        }
                       
                        sb.AppendLine(s);
                    }

                    // Execute T-SQL against the target database
                    cmd.CommandText = sb.ToString();
                    cmd.CommandTimeout = timeout;

                    cmd.ExecuteNonQuery();
                }

            }
            this.Response.Write("T-SQL file executed successfully");
        }
        catch (Exception ex)
        {
            this.Response.Write(String.Format("An error occured: {0}", ex.ToString()));
        }
        finally
        {
            // Close out the connection
            //
            if (conn != null)
            {
                try
                {
                    conn.Close();
                    conn.Dispose();
                }
                catch (Exception e)
                {
                    this.Response.Write(String.Format(@"Could not close the connection.  Error was {0}", e.ToString()));
                }
            }
        }                      
               
       
         %>
</body>
</html>

The setTimeout() method calls a function or evaluates an expression after a specified number of milliseconds.

use  javascript settimeout() method just to execute a method after some interval of time
the syntax to use this is :

setTimeout(code,millisec)

Example :
<html>
<head>
<script type="text/javascript">
function timedMsg()
{
var t=setTimeout("alert('I am displayed after 3 seconds!')",3000)
}
</script>
</head>
<body>

<form>
<input type="button" value="Display timed alertbox!" onclick="timedMsg()" />
</form>

</body>
</html>