Thursday, 26 June 2014

Setting a file's date/time to be the current date/time

I'd always used any app I had to hand or created one in my favourite programming language at the time.

I've just come across and needed to share:

  • Changing the time and date of a file
    If you want to assign the current time and date to a file without modifying the file, use the following syntax:
    copy /b Source+,,
    The commas indicate the omission of the Destination parameter.

Tuesday, 24 June 2014

Where's my .asmx debugging gone?

I wanted to simplify the deployment of a web service and provide the client with the source so that we could do some fault analysis.

I'd already supplied a .asmx with (some of) the code behind.
  <%@ WebService Language="C#" Class="Foo.Bar.DoStuff" %>

with the class Foo.Bar.DoStuff in a Foo.Bar assembly xcopy's to the web service's 'bin' folder.

All well and good...

Thursday, 19 June 2014

PRE tags in HTML copy confuses other HTML editors

I use Microsoft's Productivity Power Tools in Visual Studio and one of the features it gives me is the ability to copy my code out as HTML - so I can paste it to sites such as this.

This is usually great, but the default PRE tag that surrounds each code snippet can confuse other sites where the PRE tag is interpreted as 'any text before the next </pre> is literal'.

Fortunately the HTML Copy options allow me to specify the markup before/after each code snippet.

With the default 'BeforeCodeSnippet' being:

  <pre style="{font-family}{font-size}{font-weight}{font-style}{color}{background}">

I can now change this from PRE to SPAN and all seems well with the world.

Wednesday, 18 June 2014

Asynchronous http handlers

I had a synchronous Http Handler, let's call it 'GenericHandler'.
It was timing out in production, but not under development.
It seems that if you set debug="true" in your web.config it's designed not to time out (you wouldn't want timeouts while you're debugging now would you).

So to test this I turned off debugging and set a short timeout


<?xml version="1.0"?>
    <compilation debug="false">
    <httpRuntime executionTimeout="5"/>

There aren't enough TraceListener's in the world...

... so here's one of mine.

I got fed up with the process information polluting my console window so here's my ConsoleTraceListener which displays the Date/Time in the header (if you specify TraceOptions.DateTime) and only displays the event type if it's not TraceEventType.Information.

File name lengths can't reliably exceed 260 characters

It's astonishing to think that the developers of C# didn't take the opportunity to remove this arcane restriction especially since (most of) the underlying Windows APIs CAN!

Most Unicode Windows file-based APIs accept a canonicalised filename with the prefix '\\?\' or '\\?\UNC\' thus allowing file names of (approximately) 32,767 characters.

See: for details.

Here's a simple example of a replacement for File.Copy which uses this prefix and the relevant APIs.

Friday, 13 June 2014

Manipulating WriteableBitmap's back buffer

Things I've found about WriteableBitmap's back buffer;
  • It's at a fixed location in memory for the lifetime of the object
  • Some of the methods take byte arrays, others will take struct arrays
I wanted to 'pan' the image.  I didn't want to use a Transform because I wanted the Image to remain at the same location, but the bitmap being displayed to appear to move about so that I could have the appearance of an infinite canvas to work with as I was working on a simple Mandelbrot viewer.