.NET / C#
I love programming in .NET / C#. Have been doing it since 2004 now. Much has changed since: the .Net framework is got more libraries, NuGet was a game-changer and even C# itself is evolving with lambda and dynamic.
And now .Net has evolved to Standard and Core with support for other platforms like Linux / Docker. Things are getting easier and faster.
Auto fill settings objects with .config values
Lately I’ve been playing around with some API’s. Most of them need a bunch of settings that I’m storing them in my config files. I found myself doing the same work over and over again: creating a settings class, filling the class with information and using it. So I came up with a way to leverage reflection to fill my setting classes with .config values.
Convert HTML to SVG using CloudConvert and C#
HTML is often easier to generate than SVG. Can it be converted to SVG? I’ve found a cloud service with an API that does a nice job converting various formats: CloudConvert. I ended up implementing a small part of their API to do the conversion.
How to download a URL and get its MIME type using the C# WebClient?
A while back I needed to download a URL and determine the MIME type. Fortunately many web servers will send the MIME type of the resource back to the client (so browsers even require it). Here is a snippet of C# code that does the trick.
Fixing IE Quirks Mode in ASP.Net
Quirks mode refers to a technique used by some web browsers for the sake of maintaining backward compatibility with web pages designed for older browsers, instead of strictly complying with W3C and IETF standards in standards mode. Here’s how to force IE into submission by adding a DLL to ASP.Net.
A (slightly) better WebClient class supporting cookies and headers
Sometimes you’ll need a (slightly) better C# WebClient that’s able to store/retrieve cookies, prevent redirects or retrieve the HttpStatusCode of a request. I’ve created a small class that facilitates these features.
How to scrape a photo from a Twitter Photo URL with C#
Twitter uses its url shortener to place photo’s in Tweets. I’ve tried processing these URLs in the browser, but cross site scripting measures prevented me from processing the result with jQuery.
I decided to resolve it in C# (as I’m using ASP.Net). The following script leverages a WebClient and a regular expression to extract the photo URL from the shortened URL. This code could be added to a handler or a webservice that can be called from script.
Seek Position of a String in a File or FileStream
Yesterday I was working on a little bit of code to sniff out some XMP without having to worry about reading a file at a certain pre-defined position. XMP, being just plain XML, can be found by matching a string. After some googling I’ve found out that…