Hello Devz, Do you have a web or WPF application that needs email address validation? Regex (regular expression) can help you. This post outlines a simple email validation regex that you can use straight away. What is a regex? A regular expression (regex for short) describes a search pattern using a particular text string. It’s […]
C# – Natural Comparer
We all had the issue with an OrderBy on a collection of String, having that kind of result: Test1 Test10 Test2 Test20 Test3 Instead of: Test1 Test2 Test3 Test10 Test20 Here is the solution: public class NaturalComparer : Comparer<string> { public override int Compare(string x, string y) { if (x == y) return 0; string[] […]
C# – Retry Pattern with Polly
Hello devz! Typically, we want to get data from a distant service. This service can be slow, could not respond, or just be down… But can we still be robust in our application? Using the Retry Pattern with Polly, you can! The Retry Pattern allows us to retry a task in case of exceptions, can […]
C# – DistinctBy extension
Hello devz, The Distinct extension from System.Linq is really useful but the DistinctBy a property is missing. So we will create our own DistinctBy extension. No worries, it’s really easy. What is DistinctBy? DistinctBy is a very simple extension snippet for C# which allows the developer to remove duplicated objects in a collection based on […]
C# – Verify if it’s a network path
Hello, An easy way to determine if the path is a network path: [DllImport(“shlwapi.dll”)] public static extern bool PathIsNetworkPath(string pszPath); Yes, that’s all… Bye bye
C# – Check Write Access To Folder
Hi, An easy way to know if the user have write access to a folder can be done this way: public static bool HasWriteAccessToFolder(string folderPath) { try { // Attempt to get a list of security permissions from the folder. // This will raise an exception if the path is read only or do not […]
C# – Timer Elapsed
Time is money! But how do you manage the time in code? The simplest way of doing it is by using a Timer (System.Timers): using System; using System.Timers; namespace TimerEvent { class Program { static void Main(string[] args) { var keyPressed = false; const int delay = 1000; //Define the delay for the Timer var […]
C# – Determine the available space on a network drive
Hi peeps, Today at work I had an issue with a shared drive on the network which has a quota. So I was wondering how to know if the allowed space is already full or not. According to my readings on Google, there are only two methods that works for a network drive: WMI or […]
C# – Coma and Dot decimal separator
Hi peeps, You probably know the common issue with the decimal seprator. Depending on the country, the keyboard or what your client wants (which can be variable…), the separator will be a coma or a dot (or even something else…). In my case, the Culture is “en-US“, on a Belgian keyboard where the decimal separator […]
Share your Windows WiFi – Make your HotSpot – no app needed
Useful tip when you’re travelling and you are in a hotel where they give you only one voucher for one device. Use that voucher on your Windows 10 and you will be able to share your Internet connection with your other devices. No software needed, Windows 10 have a scriptable command called NetSh which is […]