November 26, 2013

Working with SandCastle Problems

I created a project using the "SHFB v1.9.7.0 with Visual Studio Package". This was used to convert an old help project to the latest format. However after the conversion I had make 2 fixes to get the project to build. SandcastleHelpBuilder post conversion fixes:
  1. Ensure that in the "Project Properties" tab 'Build' option that the 'Framework Version' field is set to '.NET Framework 2.0', the framework version of the compiled source code.
  2. Ensure that in the "Project Properties" tab 'Paths' option that the 'Working files path' field is set to 'Working\'.

November 6, 2013

Path Extension Class

This helper creates a temporary file with the given extension.
public static class PathExtensions
 // Create a temporary file with a specific file extension
 public static string GetTempFileName(string extension)
  string tempFileName = Path.GetTempFileName();
  string newtempFileName = tempFileName.Replace(".tmp", extension);
  File.Move(tempFileName, newtempFileName);
  return newtempFileName;

November 5, 2013

Guid String Formats

Most concise form is
 string guid = Guid.NewGuid().ToString("N");
There are other formats as well The ToString(string format) method can format a guid in one of several ways:
"N" - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx (32 digits)
"D" - xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx (32 digits separated by hyphens)
"B" - {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} (same as "D" with addition of braces)
"P" - (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx) (same as "D" with addition of parentheses)
"X" - {0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}
The Guid can be shortened as a string by using Base64 encoding:
//Compress the given Guid as a base64 string that is 22 characters long.
private static string ToShortString(Guid guid)
  string encoded = Convert.ToBase64String(guid.ToByteArray());
  return encoded.Substring(0, 22); // Last 2 characters are always ==