Monday, June 27, 2011

SMS sending via Service Provider API in C#

This is the sample code which is use for sending SMS from window application in c#

using System.Net;
using System.IO;

 String strname = "http://isms.sapstech.com/pushsms.php?username=nishantvipul&password=12345&sender=VIPUL&to=9708094346,9263870334,94312350123&message=Hi%20This%20is%20a%20test%20message.&priority=2";
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(strname);

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            StreamReader reader = new StreamReader(response.GetResponseStream());

            string result = reader.ReadToEnd();
            MessageBox.Show(result);

Read the Excel file via C# using OLEDB class

This article explains how to read excel files using c sharp in windows applications-


using System.Data.OleDb;
try
            {
                string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + @"\Courier.xls;Extended Properties=ImportMixedTypes=Text;Excel 8.0;HDR=Yes;IMEX=1;";

                //You must use the $ after the object you reference in the spreadsheet
                OleDbDataAdapter adap = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", connStr);

                DataSet ds = new DataSet();
                adap.Fill(ds, "Courier");
                dataGridView1.DataSource = ds.Tables["Courier"].DefaultView;
               

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

Explanation of the above code:
Here I used OleDb to read the excel file. The excel file resides with exe file as Courier.xls.
Sheet1 is the name of excel sheet.
Courier is the name of file so i am using the same name in filling the DataSet.
Now at last the data is filled into dataGridView.
Now if you are not able to read the integer value or any value other then text then
include the
Extended Properties=ImportMixedTypes=Text;Excel 8.0;HDR=Yes;IMEX=1 property in connection string.

The above code can also be used in a web application, for this you need to replace the Application.StartupPath with Server.MapPath

Useful link to know more about excel file using c# : http://csharp.net-informations.com/excel/csharp-read-excel.htm