Handlebars

Handlebars is a fantastic templating engine which is available for .NET. It’s similar to Mustache, which I tend to prefer, but Handlebars has more features that can be very useful. This is a basic example showing how easy it is to apply a template. // <package id=”Handlebars.Net” version=”1.7.1″ targetFramework=”net40″ /> // {{ “{{” }}{ triple-stash to […]

Get EXIF date from photo

It’s not straightforward to retrieve the EXIF date from an image. Here’s a method to retrieve it using the MetadataExtractor package. It looks for the appropriate date, and if not found, falls back to the file properties. // <package id=”MetadataExtractor” version=”2.0.0″ targetFramework=”net40″ /> static DateTime GetImageDate(string file) { var directories = ImageMetadataReader.ReadMetadata(file); ExifSubIfdDirectory subIfdDirectory = […]

Configuration in .NET Core

Here’s some basic examples for reading from a configuration file: 1) Create an appsettings.json file in your project. 2) Add this to your csproj file, so that it gets to your output directory: <ItemGroup> <None Update=”appsettings.json”> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </None></ItemGroup> 3) Install the appropriate NuGet packages: dotnet add package Microsoft.Extensions.Configuration.Jsondotnet add package Microsoft.Extensions.Configuration.Binder 4) Add data to […]

Config for SMTP

<system.net> <mailSettings> <smtp deliveryMethod=”Network”> <network host=”smtp.something.something” defaultCredentials=”false” enableSsl=”true” password=”1122334455″ port=”587″ userName=”postmaster@example.com” /> </smtp> </mailSettings></system.net>

AWS Cloud9 IDE

AWS Cloud9 IDE is incredibly easy to set up, and is an affordable way to do some work outside of our normal development machine. If you have an AWS account already set up, building a Cloud9 machine just takes about 1 minute, and is immediately available for use. When you’re done, the EC2 instance will […]

ASP.NET Embedded Resource

You can compile binary or text files into the application assembly – here’s the basic idea. Add the file to the project in Visual Studio, and in the Properties, mark it as “Embedded Resource”. The name of the resource is the default namespace for the project + relative namespace (folder structure) + filename. This is […]

Add EXIF date to photo

If you have a photo that you need to add a timestamp to the EXIF information, you can use the following .NET code. Apparently there are a ridiculous number of formats and standards which are incompatible with each other and conflicting, but from what I’ve found, this should cover regular use cases. I’m sure there’s […]

Local Storage in the browser

Local storage lets you store things indefinitely in the user’s browser, specific to your site. This can be used for all kinds of things, like caching dropdown values, storing user information, keeping client-side shopping carts, whatever else you can think of. It’s a simple store, just string-value pairs, so if this doesn’t suit your needs, […]

SQL XML Nested Types

declare @people table (id int, name varchar(50));insert @people values (1, ‘John’);insert @people values (2, ‘Mary’);insert @people values (3, ‘Pat’);declare @cars table (id int, model varchar(50), person_id int);insert @cars values (1, ‘Corvette’, 1);insert @cars values (2, ‘Mustang’, 1);insert @cars values (3, ‘Viper’, 2);select p.id [@id] ,p.name [@name] ,( select model [@model] from @cars where person_id = […]

SQL Table Valued Parameters in .NET

private static SqlDataRecord CreatePersonRecord(int id, string name) { var metaData = new[] { new SqlMetaData(“Id”, SqlDbType.Int), new SqlMetaData(“Name”, SqlDbType.VarChar, 50) }; var record = new SqlDataRecord(metaData); record.SetInt32(0, id); record.SetString(1, name); return record;}private SqlDataRecord[] GetPersonRecords() { retun new[] { CreatePersonRecord(1, “John Doe”), CreatePersonRecord(2, “Jane Doe”) };}using (var conn = new SqlConnection(cs)) { conn.Open(); using (var comm […]