Sitecore 5.3 and ImageURI

If you assign the path of a media item to a Image.ImageUrl in code behind it will not find the image unless you prefix the path with a /, see the example code below:

// ensure that the url has a / before any ~
string spotItemURL = myImageField.Path;
if(spotItemURL.StartsWith("~"))
  spotItemURL = /" + spotItemURL;

If you do not make the above check the image will be renders in HTML as follows:

<img src="~/media/60DAF58AD915497A893315F10CCEBD94.ashx" />

And both IE & Firefox cannot find the image, if you prefix the url with a /, using the code above the output will be as follows:

<img src="/~/media/60DAF58AD915497A893315F10CCEBD94.ashx">

PDF module designed for Sitecore

Right now we are finishing off the new PDF Module for Sitecore. If you would like to generate PDF documents from your web pages, and structure them in Books, complete with front page and a table-of-contents, this module is for you.
Right now we are planning to offer the module in 2 versions. The first version will only be able to render single web pages as PDF documents. The second one will also be able to create PDF books from pre-generated PDF documents.

Imagine this setup: You are the web master of the new “United States Constitution” web site. Your site must offer the United States Constituion not only as web pages but also as a complete book. The book must be customer-specific; containing only the chapters selected by the user.

First you set up your web site. The United States Constitution is organized in Sitecore, each chapter has it’s own Sitecore item, sub-chapters are sub-items.

Then you set up a new device, the PDF device. This device renders one complete chapter with sub-chapters as one webpage.

The PDF device is used by the PDF Module to create pre-generated PDF documents stored on the hard-drive of the web server, complete with a table-of-contents for each chapter.
In the PDF module you set up which pages to render as PDF. Your PDF Book needs header and footers, page numbers, date of publishing, some graphics to impress the management and so on. All these elements are added to each page using Layers.

Finally you create a Book page, where your users can select the chapters to add to his or hers own personal copy of the constituion. When presing “Go” your code-behind quickly collects the selected pages and combines then with a frontpage and a table-of-contents containing only the chapters chosen by the user. The book is then streamed to the user, complete with bookmarks and document properties.

Posted in Sitecore 5. Tags: , . 3 Comments »

MD5 hash function

In cryptography, MD5 (Message-Digest algorithm 5) is a widely used cryptographic hash function with a 128-bit hash value. As an Internet standard (RFC 1321), MD5 has been employed in a wide variety of security applications, and is also commonly used to check the integrity of files. An MD5 hash is typically a 32-character hexadecimal number. Recently, a number of projects have created MD5 “rainbow tables” which are easily accessible online, and can be used to reverse many MD5 hashes into strings that collide with the original input.” (source: Wikipedia).

To make a MD5 algorithm in C# you may use the MD5CryptoServiceProvider which is standard in the C# library:

public static string MD5(string text)
{
  byte[] textBytes = System.Text.Encoding.Default.GetBytes(text);
  try
  {
    System.Security.Cryptography.MD5CryptoServiceProvider cryptHandler;
    cryptHandler = new System.Security.Cryptography.MD5CryptoServiceProvider();
    byte[] hash = cryptHandler.ComputeHash(textBytes);
    string ret = "";
    foreach (byte a in hash)
    {
      if (a<16)
        ret += "0" + a.ToString ("x");
      else
        ret += a.ToString ("x");
    }
    return ret ;
  }
  catch
  {
    throw;
  }
}