Bind Categories in dropdownlist with sitefinity

May 27, 2014

Programmatically populate DropDownList with Taxonomy Categories,

In the sitefinity sometime you need to bind collection list/Categories into repeater grid or drop down.

Below code snippet will helps you for it

TaxonomyManager manager = TaxonomyManager.GetManager();
var taxonomy = manager.GetTaxonomies<HierarchicalTaxonomy>().Where(t => t.Name == "Categories").SingleOrDefault();
var categoryList = taxonomy.Taxa.ToList();
drpEventTypes.DataSource = categoryList;
drpEventTypes.DataTextField = "Title";
drpEventTypes.DataValueField = "Id";

Bind Enum data type in dropdown list

February 10, 2014


Here is a code snippet for bind enum data type in drop down list with datasource property.

var enumerationType = typeof(Entity.ProgramType);
 var dictionary = new Dictionary<int, string>();

foreach (int value in Enum.GetValues(enumerationType))
 var name = Enum.GetName(enumerationType, value);
 dictionary.Add(value, name);
 ddlProgramType.DataSource = dictionary;
 ddlProgramType.DataTextField = "value";
 ddlProgramType.DataValueField = "key";
 ddlProgramType.Items.Insert(0, new ListItem("---Both---", "0"));

you will get your dropdown binded with enum ūüôā

Split string with multi-delimiter with c#

February 10, 2014


Here is a trick for split string by another string

Or we can call split string by multi delimiter.

string data = "THExxQUICKxxBROWNxxFOX";

return data.Split(new string[] { "xx" }, StringSplitOptions.None);

this code returns you array by split main string with “xx”.

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
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";
string AuthToken = "get token from";
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
if (message != null)
lblMessage.Text = message.Status;
if (message.Sid != null)
lblMessage.Text = lblMessage.Text + " SID: " + message.Sid;
lblMessage.Text = "Error";
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

Get updated table list between particular duration

October 2, 2013


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
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)
FROM sys.dm_db_index_usage_stats
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


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.



Datatable to Excel file without using a loop

October 2, 2013


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.Charset = "";

// set the response mime type for excel
response.ContentType = "application/";
// 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;

Funny interview questions

August 1, 2013

If you’d want to annoy an interviewer after one of their “original” questions.
Here are some ideas, feel free to come up with your own…

1. If you were to win £1 million what would you do with the money?
Buy this company.
2. What do you think is the most useful function in Excel?
The exit button.
3. What makes you happy about work on a Friday evening?
That there is no work on Friday evening.
4. How do you fit a giraffe in a fridge?
You cut into tiny pieces until it stops struggling. Then fit each piece in the fridge.
5. What is it about this job you would least look forward to?
Your face.
6. If you were the Head of Barclays Corporate what would your strategy be with the recent European Crisis?
Stop interfering.
7. If your friend was seriously injured and you had to get him to a hospital, would you speed and go through a red light?
8. Would you rather fight a horse-sized duck or 100 duck sized horses?
100 ducks. I would stamp on each one with my foot. Their little bodies would be squashed like a grape.
9. Tell me about a time when you failed at something.
Why do you claim I ever failed at anything?
10. What are the three words that your parents would describe you with?
My parents died last month in a car accident due to a drunk driver.
11. What have you done in the past to get out of a tricky situation?
My fist, his face.
12. Why is 99% not good enough?
It’s one percent you haven’t got.
13. How many ways can you get a needle out of a haystack?
This doesn’t look like a correct sentence to me.
14. How would you explain Facebook to your Grandma?
Take a book and hit her in the face.
15. If you entered into a room full of people with different interests, what would you do?
Walk out?
16. What do you mean by ‚Äėleadership‚Äô?
I’m the boss.
17. By what criteria do you judge your own performance?
By my own.
18. Which football team do you support?
The one showing my company’s logo.
19. What is the main thing that gets you out of bed each morning?
The kids…
20. Describe the hardest decision you have faced in the past 12 months.
Shoot the wife or the dog?
21. Who is your biggest hero?
Chuck Norris.
22. Give me an example of your extreme levels of tenacity.
I’m still here after 22 of your stupid questions.
23. In a fight between a lion and a tiger, who would win & why?
Lions and tigers live in different areas and would not encounter one another.
24. How would your delegates describe you?
The boss.
25. Do you think the quality of our menswear products are as high as our home department products?
“high” is not how I would describe it.