The Unix calendar starts at 01/01/1970. This post will show you how to convert any DateTime value into a Unix time stamp. private const string…
There is no built-in way to discover the MAC address of your network adapter in .NET. Using the following function the MAC address that belongs…
The following code contains extension methods for the random class. One method will create random dates between a given minimum and maximum. The second method…
The following code removes the BOM (Byte Order Mark) from texts. Some text editors add that while saving files. Sometimes this leads to problems while…
Path of the executing assembly: public static string GetExecutingAssemblyPath() { string codeBase = Assembly.GetExecutingAssembly().CodeBase; UriBuilder uri = new UriBuilder(codeBase); string path = Uri.UnescapeDataString(uri.Path); return Path.GetDirectoryName(path);…
If you need to show a list of languages, or more general CultureInfos, you might want to sort them by the name they show up…
Calculating a leap year The correct calculation of a leap year was first introduced by pope Gregor in 1582. The Gregorian Calendar is still commonly…
Not all possible characters are suitable for file names. For example path separators cannot be used for file names. This changes any string into a…
The following code snippet checks if the current user as administrator rights: /// <summary> /// Checks if user has administrator rights /// </summary> public static bool UserIsAdmin() { WindowsIdentity identity = WindowsIdentity.GetCurrent(); WindowsPrincipal principal = new WindowsPrincipal(identity); return principal.IsInRole(WindowsBuiltInRole.Administrator); } If the application requires…