How to make String.Contains case insensitive?

The string.Contains() method in C# is case sensitive. And there is not StringComparison parameter available similar to Equals() method, which helps to compare case insensitive. If you run the following tests, TestStringContains2() will fail. Other option is using like this. And here is the case insensitive contains method implementation. And here is the modified tests.Read More

How to broadcast a message from outside SignalR hub

Broadcasting a message from SignalR hub is pretty straight forward, but sometimes you may need to do the same from outside the hub, like from MVC controller or a Web Page. This snippet will help you to broadcast messages from outside hub. In this MySampleHub is the SignalR hub class and Notify is the HubRead More

How to authenticate user against active directory

While developing an intranet application, I had to use Active Directory to authenticate the users. I thought I might need to use WMI. But I found a simple solution using PrincipalContext class from the System.DirectoryServices.AccountManagement namespace. You can use the ValidateCredentials() method. You need to pass the domain name as one of the parameter toRead More

How to use the Outlook Object Library to send an email

Sometimes we required to send email messages using Outlook Object Library instead of the conventional System.Net.Mail.SmtpClient class. While developing an desktop application, where I couldn’t hard code the SMTP server details and credentials. I found a solution using Outlook Object library, which will help to send email, with the current user context and credentials. HereRead More

How to handle hardware back button in Windows Phone

If you want to display an exit confirmation from your Windows Phone app, if user press the hardware back button, here is the code snippet. (It is not a recommended practice, as per Windows Phone market place certification requirements, if user pressing the back button from the application’s first page, application should exit) It willRead More