Posts in the Software Development category

Announcing the Microsoft @ GDC App


So this is nice Smile My Windows Phone app just hit the Windows Phone Marketplace (you can find it in the marketplace under Microsoft @ GDC – or just click this link to install it directly on your phone). It’s a little app that gives you details on all of the conference sessions and talks that Microsoft are sponsoring, putting on, or otherwise giving at GDC this year. (more...)

Sharing Links to your Windows Phone App

There’s a chicken and egg problem out there, and I think I can help.

It’s nice in a Windows Phone app to be able to share links to things – after all, that’s what the ShareLinkTask is for in the API.

It’s even better if you can let users share a link to your app from within your app. It removes the burden from them, and lets them get all social when they first experience that giddy moment of glee they get from using your absolutely awesome creation.

However, there’s a problem here. To share a link to your app (and have it instantly installable!) they’re going to need a link to the marketplace for your app. Unfortunately that link only gets assigned once your app is published.

So how the heck do you do that?

I got some feedback from Jarek Kowalski on the Windows Phone Certification team about this (thanks Jarek!). Apparently you can upload your XAP file to the marketplace, but not submit it, and this will give you the direct link you’re seeking. It just won’t go live until you publish, but the app-ID will be fixed from that point on, and you can just slip it into your URL.

There are some benefits to have a fixed location on the web that you can point at though, so I’m going to keep the rest of the article up as-is.

Well, you could publish it twice, but that’s slow and messy. Here’s another solution.

MS Tags To The Rescue!

A Microsoft Tag is a cute little thing kind of like a QR tag, but more colorful. In fact, they can look like this:


Now, I’m not going to suggest you go to that degree of effort… but it’s cool that you can. (And what’s cooler is that Bing Search on Windows Phone Mango has that cute little “visual search” button that you can hit, and it’ll recognize these tags automatically).

And we’ll probably need one of these things anyway, so you can advertise your app on bulletin boards at your workplace and start driving grass roots support.

So head on over here, and create one:

What This Buys You

Ok, so a tag is cool, but what does it buy you in this scenario?

It gives you a fixed endpoint for a Uri, which you can dynamically change later.

This is actually quite a big and useful deal, and it’s just a side-effect of how the Tag service works, but we can use it to our advantage.

So you can use the link that the tag represents as the link your app shares out. And later on, once it’s published, you just replace the link with something else.

What’s even cooler is that it’ll let you redirect users of other mobile OSes to different locations if you want to (or if you have a version of your app for that other OS).


Killing several birds with one stone. Gotta love it. Here’s the final result:


And… if you really want to, you can create a QR code as well from the same place. All the more reason to use the tag service! Smile


But this isn’t the part you want for your app. For your app, Download the resulting tag, and download it as a URL (it’s one of the download formats). Take that URL, and put that in your app. For example, the one I generated is:

Hey presto. Redirect that puppy anywhere you want by editing your tag later. For now, my tags and that URL redirect you to a page saying “Your mobile device does not support this content”. It’ll go live some time in the next couple of weeks… until then, enjoy!


Fixing Byte-Order-Mark issues with Wordpress on IIS

One common problem – it seems – with Wordpress just plain acting funky on IIS is that occasionally, byte-order-marks get inserted into the UTF-8 PHP documents that make up the Wordpress code.

Sometimes these come in as part of templates and plugins, other times they just magically* appear.

If you’ve got Visual C# (or Visual C# express), here’s a little nugget of code you can use to strip them out. No warranties. No expressed suitability for a given purpose. Just free code I wrote. Free, crappy, one-off, single-purpose code. But it works. Compile it up, and run it, and watch it go.

I recommend running it in two passes:

  • Generate a list of files to check using DIR /S *.* /B /A-D > out.cmd
  • Modify that list to call BOMFix on each file (e.g. BOMFix c:\myfile\app.php ). Make a note of which files have a BOM mark
  • Run it again, with /F as the second argument (e.g. BOMFix c:\myfile\app.php /F ). This will strip the BOM from the files.
  • Throw your files back up onto the server.

And for your viewing pleasure, here’s the code:

using System;
using System.IO;

namespace BOMFix
    class Program
        static void Main( string[] args )
            if ( args.Length == 0 )

            bool bHasBom = FileHasBOM( args[ 0 ] );

            if ( bHasBom )
                Console.Out.WriteLine( "{0} has a BOM", args[ 0 ] );
                if ( args.Length == 2 && (args[1] == "/F" || 
                     args[1] == "/f") )
                   StripBOM( args[0] );
                   Console.Out.WriteLine( "Removed BOM from {0}",
                                           args[ 0 ] );

        const long READSIZE = 8192;

        public static bool FileHasBOM( string path )
            FileStream s = new FileStream( path, FileMode.Open,
                                FileAccess.Read, FileShare.Read );
            long fileLen = s.Length;
            if ( fileLen < 3 )
                return false;

            byte[] file = new byte[ 3 ];
            s.Read( file, 0, 3 );

            return ( file[ 0 ] == 0xEF && file[ 1 ] == 0xBB &&
                     file[ 2 ] == 0xBF );

        public static void StripBOM( string path )
            FileStream s = new FileStream( path, FileMode.Open,
                               FileAccess.Read, FileShare.Read );
            s.Seek( 3, SeekOrigin.Begin );
            long readleft = s.Length - s.Position;
            byte[] buffer = new byte[ READSIZE ];

            string tempFileName = Path.GetTempFileName();
            FileStream outStream = new FileStream( tempFileName,
                FileMode.Truncate, FileAccess.Write, FileShare.None,
                8192, FileOptions.SequentialScan );
            while ( readleft > 0 )
                int chunkSize = (int)Math.Min( READSIZE, readleft );
                if ( s.Read( buffer, 0, chunkSize ) != chunkSize )
                    throw new Exception( "Not enough data! File error?" );

                outStream.Write( buffer, 0, chunkSize );

                readleft -= chunkSize;



            File.Replace( tempFileName, path, null );

*Yes, I know, not actually magically… but no-one seems to have root-caused it.