Friday 28 March 2014

Bulk SMS Gateway C# Code for HTTP API

Today , I am going to show you how to send BULK SMS from any Website or Software. Every Bulk SMS provides uses SMS Gateway that are of two types :
1. Promotional
2. Transactional
First one is used to broadcast SMS to multiple users at a time which take minimum 5-10 minutes of time to deliver SMS. Messages are sent through low priority gateways. You won't get unique Sender ID.
On the other hands , Transactional type SMS uses high priority network and also allow use of unique Sender ID.
Many Bulk SMS provider companies gives API to intregate with custom web and software application. Though implemention of SMS gateway API is simple but its quite tricky.
Checkout below code which demonstrate send multiple SMS on one click:


protected void Button5_Click(object sender, EventArgs e)
    {
       
        string[] strArray = sms.Split(new char[1]
      {
        ','
      });

        int count = strArray.Count();
        
        try
        {
           WebClient client = new WebClient();
            // Add a user agent header in case the requested URI contains a query.
            for (int i = 0; i < count; i++)
            {
                client.Headers.Add("user-agent", "Mozilla/4.0(compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
              baseurl = "http://login.redseo.in/API/SendMessage.ashx?user=test&password=0123&phone="+strArray[i]+"&text="+TextBox5.Text+"&type=t&senderid=TESTIN";
               
                 data = client.OpenRead(baseurl);
                 reader = new StreamReader(data);
                string s = reader.ReadToEnd();
            }
            data.Close();
            reader.Close();
           
            //return (s);
        }
        catch (Exception exc)
        {
            Label128.Text = "Failed.";
            
        }
    }
Read More

Thursday 27 March 2014

[Solved ] DateTime Conversion Problem in Dot Net C Sharp

Today, i am providing a custom Date Time Class that can be used to solve the issues related to Date Time Conversion problem in Dot Net. The code provided here is in C#. You can directly use this class in your project and call the related methods which is required.

Why Date Time Conversion problem occurs?


Different PCs have different Date and Time format based on choice and locale. In sql server, [datetime] type datatype always store Date and Time in yyyy-MM-dd HH:MM:SS.000 format. So if we try to insert Date other then this standard format, then sql server shows the error which says ,"Conversion from nvarchar/varchar data type to datetime data type failed." . So if you already use this standard format then you don't require Date Conversion class. Some we don't know what will be format of inpu date and time. In this case, use of following class code is very helpful:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Globalization;

/// <summary>
/// Summary description for DateTimeClass
/// </summary>
public class DateTimeClass
{
    //METHOD 1
    // use only when you want to convert any input time format to system time format
    // Both method parse only date seperator like [ - , / ] etc
    // IT NOT CONVERT MM/dd/yyyy to dd-MM-yyyy . it only convert dd/MM/yyyy to dd-MM-yyyy 
   
    DateTime dateTime;
   
    DateTime dtime;
    //get current date format
    string dateformat = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern;
    //CALL WHEN YOU WANT TO CONVET INPUT DATE STRING INTO SYSTEM DATE STRING
    public string DTC(string input)
    {
     
         

        DateTime.TryParse(input , out dateTime);

        return dateTime.ToShortDateString();
       
    }

    public DateTime DTCC(string input)
    {



        DateTime.TryParse(input, out dateTime);

        return dateTime;

    }
    // CALL WHEN U WANT SYSTEM DATE TIME FORMAT
    public string DTF()
    {
        string input = DateTime.Now.ToString();

        DateTime.TryParse(input, out dateTime);


        return dateTime.ToShortDateString();

    }

    public string DTPE(string input)
    {
        string dtformat = "dd/MM/yyyy";

        CultureInfo cprovider = CultureInfo.InvariantCulture;

        return DateTime.ParseExact(input, dtformat, cprovider).ToString("dd/MM/yyyy");
     
     
    }


    //METHOD 2
    // use this function when you want to convert fixed input time format to system time format
    // this method parse date seperator like [ - , / ] etc
    // IT CAN CONVERT MM/dd/yyyy to SYSTEM DATE WHICH MAY BE IN dd-MM-yyyy TYPE FORMAT.
    // DATE TIME CONVERT FIXED INPUT DATE FORMAT
    public string DTCFF(string input)
    {

        dateTime = DateTime.ParseExact(input, "dd/MM/yyyy", System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat);

        return dateTime.ToShortDateString();

    }

    // DATE TIME CONVERT FIXED INPUT DATE FORMAT
    public string DTCF()
    {
        string input = DateTime.Now.ToShortDateString();
        dateTime = DateTime.ParseExact(input, "dd/MM/yyyy", System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat);

        return dateTime.ToShortDateString();

    }


    //DATE TIME  FIXED INPUT FORMAT 

    public string DTFF(DateTime sql)
    {

        sql = DateTime.ParseExact(sql.ToString(), "dd/MM/yyyy", System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat);

        return sql.ToShortDateString();
    }


    //BREAK SYSTEM DATE INTO DESIRED FORMAT
    public string DTN()
    {
        DateTime dt = DateTime.Now;
        string d1, m1, y1;
        d1 = dt.Day.ToString();
        m1 = dt.Month.ToString();
        y1 = dt.Year.ToString();


        return d1 + "/" + m1 + "/" + y1;
    }

    public string DTNN(DateTime dt)
    {

        DateTime dt1 = new DateTime();
        dt1 = dt.AddYears(1);
        DateTime dt3 = new DateTime();
        dt3 = dt1.AddDays(-1);
        string d1, m1, y1;
        d1 = dt3.Day.ToString();
        m1 = dt3.Month.ToString();
        y1 = dt3.Year.ToString();
        return d1 + "/" + m1 + "/" + y1;

    }

}

Read More

Blogger