Tuesday, August 6, 2013

MAIL send from ASP.net C#

Here is a simple example for MAIL sending from ASP.net and C#

Hope it will help you



private void MAILSEND(string strDecision)
    {
        SmtpClient smtp = new SmtpClient();
        MailMessage mail = new MailMessage();

        mail.From = new MailAddress(Originator_mail address);
        mail.To.Add(mail_address);

mail.Subject ="Subject";
       mail.Body="Body";
smtp.Host ="Host_Addr";
smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtp.Port = 25;
            smtp.Send(mail)
}

client side popup message in asp.net

client side popup alert message for asp.net

1. please select the button properties
2. go the the "OnClientClick" properties
3.paste this syntax
 return confirm('Are you sure......?');


how to use session variables in ASP.Net

session variables is a important and necessary variable in asp.net, specially in web programming.
programmer can use session variable to keep the information for the particular session. i.e if you fill a session variable with data you can use this variable of dada any point of data for the particular session.

below is the example of session variable

Session["LoginUserID"]=txtuserid.text;

Web Service in C# with XML return format

I am writing here a web service in C# for xml output. please check the below example. this will surely help you.

[WebMethod(Description = "User Authentication")]
    [ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
    public List LoginAuthentication(string struserID, string strPassword)
    {
        SqlConnection objConnection = new SqlConnection(strconnectionString);
        SqlCommand objCommand = new SqlCommand("SELECT * FROM UserInformation where UserID='" + struserID + "' and Password='" + strPassword + "' ", objConnection);
        DataSet objDataSet = new DataSet();
        SqlDataAdapter objDataAdapter = new SqlDataAdapter(objCommand);
        objDataAdapter.Fill(objDataSet, "reading");
        objConnection.Close();
        List colLatestUpdate = new List();

        foreach (DataRow rs in objDataSet.Tables[0].Rows)
        {
            LoginAuth objLU = new LoginAuth();
            objLU.Status = 1;
            colLatestUpdate.Add(objLU);          
        }

        if (objDataSet.Tables[0].Rows.Count == 0)
        {
            LoginAuth objLU = new LoginAuth();
            objLU.Status = 0;
            colLatestUpdate.Add(objLU);
        }
        XmlSerializer LatestUpdateserialize = new XmlSerializer(typeof(List));

        System.IO.MemoryStream ms = new System.IO.MemoryStream();
        LatestUpdateserialize.Serialize(ms, colLatestUpdate);
        ms.Position = 0;
        List LatestUpdateElement = (List)LatestUpdateserialize.Deserialize(ms);
        return LatestUpdateElement;
    }



///Entity Class

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

///
/// Summary description for LatestUpdate
///

public class LoginAuth
{
    public LoginAuth()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    private int _Status = 0;
    private string _userid;
    private string _mobile;
   
    public int Status
    {
        get
        {
            return _Status;
        }
        set
        {
            _Status = value;
        }
    }
    public string UserID
    {
        get
        {
            return _userid;
        }
        set
        {
            _userid = value;
        }
    }
    public string Mobile
    {
        get
        {
            return _mobile;
        }
        set
        {
            _mobile = value;
        }
    } 
}



Web Service in C# with JSON return format

You can very easily write web service with JSON data return format.

please check below method, this may help you.

[WebMethod(Description = "Gets Student information")]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public string GetStudent()
    {
        SqlConnection objConnection = new SqlConnection(strconnectionString);
        SqlCommand objCommand = new SqlCommand("SELECT * FROM Student", objConnection);
        DataSet objDataSet = new DataSet();
        SqlDataAdapter objDataAdapter = new SqlDataAdapter(objCommand);
        objDataAdapter.Fill(objDataSet, "reading");
        objConnection.Close();
        // Create a multidimensional jagged array
        string[][] JaggedArray = new string[objDataSet.Tables[0].Rows.Count][];
        int i = 0;
        foreach (DataRow rs in objDataSet.Tables[0].Rows)
        {
            JaggedArray[i] = new string[] { rs["Name"].ToString(), rs["Roll"].ToString(), rs["Class"].ToString() };
            i = i + 1;
        }
        // Return JSON data

        JavaScriptSerializer js = new JavaScriptSerializer();
        string strJSON = js.Serialize(JaggedArray);
        return strJSON;

    }

how to do type casting in c#

frequently we need casting in c#. type casting is one of them as like below

private void findtotalstudent()
{
int count=(int)gettotalstudent()
}

private int gettotalstudent()
 {
int totalcount=0

// find out total count from  database

return totalcount;
}

Wednesday, January 2, 2013

Simple Java based SMPP Client Source Code to send SMS


This program needs the following java files to function.
1. SerialConnection.java (This file is used to connect to your COM port from your java program)

2. SerialConnectionException.java (This file is for handling serial connection exceptions in your Java program)

3. SerialParameters.java (This program is used to set your COM port properties for connecting to your com port from your java program)

4. Sender.java (This is the program that implements runnable and sends SMS using the serial connection)

5. SMSClient.java (This java class is the main class that can be instantiated in your own java program and called to send SMS. This program in turn will use all the above four files internally to send out your SMS).

/*

 *
 * A free Java sample program 
 * A list of java programs to send SMS using your COM serial connection
 * and a GSM modem
 *
 * @author William Alexander
 * free for use as long as this comment is included 
 * in the program as it is
 * 
 * More Free Java programs available for download 
 * at http://www.java-samples.com
 *
 *
 * Note: to use this program you need to download all the 5 java files
 * mentioned on top
 *
 */
public class SMSClient implements Runnable{

  public final static int SYNCHRONOUS=0;
  public final static int ASYNCHRONOUS=1;
  private Thread myThread=null;

  private int mode=-1;
  private String recipient=null;
  private String message=null;

  public int status=-1;
  public long messageNo=-1;


  public SMSClient(int mode) {
      this.mode=mode;
    }

  public int sendMessage (String recipient, String message){
    this.recipient=recipient;
    this.message=message;
    //System.out.println("recipient: " + recipient + " message: " + message);
    myThread = new Thread(this);
    myThread.start();
//    run();
    return status;
    }
    public void run(){

    Sender aSender = new Sender(recipient,message);

    try{
      //send message
          aSender.send ();

         // System.out.println("sending ... ");

      //in SYNCHRONOUS mode wait for return : 0 for OK,
      //-2 for timeout, -1 for other errors
      if (mode==SYNCHRONOUS) {
          while (aSender.status == -1){
            myThread.sleep (1000);
          }
      }
      if (aSender.status == 0) messageNo=aSender.messageNo ;

    }catch (Exception e){

        e.printStackTrace();

    }

    this.status=aSender.status ;

    aSender=null;


  }
}

Happy New Year


Hello Everyone,

Wish you and all of your family is a very happy new year