Send SMS using Twilio REST API

October 4, 2013

Here are some helpful notes for send sms using Twilio sms API.
First you should have account on http://twilio.com/
After creating a account Go to your visual studio and
install twilio package from Nuget package manager.
Use this code to send SMS,


protected Twilio.SMSMessage SendSMS()
{
string AccountSid = "your Sid get from https://www.twilio.com/user/account/settings";
string AuthToken = "get token from https://www.twilio.com/user/account/settings";
var twilio = new TwilioRestClient(AccountSid, AuthToken);

var message = twilio.SendSmsMessage("<strong>sender num</strong>", "<strong>reciever number</strong>", "<strong>your message body here</strong>");
//Note :: sender number you will get from here https://www.twilio.com/user/account/phone-numbers/incoming
try
{
if (message != null)
{
lblMessage.Text = message.Status;
if (message.Sid != null)
{
lblMessage.Text = lblMessage.Text + " SID: " + message.Sid;
}
else
{
lblMessage.Text = "Error";
}
}
else
{
throw new Exception("Error");
}
}
catch (Exception e)
{
lblMessage.Text = e.Message.ToString();
}
return message;
}

You will get status and SID of message.
you will get more info about API from https://www.twilio.com/docs

Advertisements

Get updated table list between particular duration

October 2, 2013

Hi,

Here is a table valued function to get updated table list between particular two datetime in sql database.


CREATE FUNCTION [dbo].[GetLastUpdateTablesDetail](@FromDate datetime,@ToDate datetime)
RETURNS @trackingItems TABLE (
ID    int    identity NOT NULL,
TableName    varchar(100)    NOT NULL,
LastUpdateDate    datetime    NOT NULL,
LastScanDate datetime    NULL
)
AS
BEGIN
set @FromDate =  DATEADD(MINUTE, -1, CONVERT(VARCHAR(10), @FromDate, 101))
set @ToDate = DATEADD(DAY, 1, CONVERT(VARCHAR(10), @ToDate, 101))

INSERT INTO @trackingItems (TableName, LastUpdateDate,LastScanDate)
SELECT OBJECT_NAME(OBJECT_ID) AS TableName,
last_user_update,
last_system_scan
FROM sys.dm_db_index_usage_stats
WHERE
database_id = DB_ID(DB_NAME())    AND
OBJECT_NAME(OBJECT_ID) in (select Name from sys.tables)
AND sys.dm_db_index_usage_stats.last_user_update >= @FromDate and sys.dm_db_index_usage_stats.last_user_update <= @ToDate
order by sys.dm_db_index_usage_stats.last_user_update desc

RETURN;
END;

then run this function like

 


SELECT * FROM  [dbo].[GetLastUpdateTablesDetail]('2013/10/01','2013/10/02')

You will get output like below  snapshot,You will get table name with updated date and time.

GetLastUpdateTablesDetail

 


Datatable to Excel file without using a loop

October 2, 2013

Hello,

Using below function you can  get excel file from you datatable ,as yes without using any for or foreach loop


public void ExportToExcel(DataTable dt, string filename)
{
HttpResponse response = HttpContext.Current.Response;

// first let's clean up the response.object
response.Clear();
response.Charset = "";

// set the response mime type for excel
response.ContentType = "application/vnd.ms-excel";
// response.ContentType = "application/vnd.xls";
response.AddHeader("Content-Disposition", "attachment;filename=TestingReports.xls");

// create a string writer
using (StringWriter sw = new StringWriter())
{
using (HtmlTextWriter htw = new HtmlTextWriter(sw))
{
// instantiate a datagrid
DataGrid dg = new DataGrid();
dg.DataSource = dt;
dg.DataBind();
dg.RenderControl(htw);
response.Write(sw.ToString());
response.End();
}
}
}