Blog posts

  • Convert to BitmapImage

    March 30, 2011 | Tags: WPF, Image Library, Open source, Snippet
    Want to convert your KalikoImage (if your using C# Image Library) into a System.Windows.Media.Imaging.BitmapImage for use with for instance WPF, then here's your code (kalikoImage being your KalikoImage object):
    MemoryStream ms = new MemoryStream();
    ms.Position = 0;
    BitmapImage bi = new BitmapImage();
    bi.StreamSource = ms;

    If you instead want to convert a System.Drawing.Bitmap to a System.Windows.Media.Imaging.BitmapImage, then this is your code (myBmp being your Bitmap object):
    MemoryStream ms = new MemoryStream();
    myBmp.Save(ms, ImageFormat.Bmp);
    ms.Position = 0;
    BitmapImage bi = new BitmapImage();
    bi.StreamSource = ms;

    Once you have your BitmapImage, you can pass that into a System.Windows.Controls.Image:
    System.Windows.Controls.Image img = new System.Windows.Controls.Image();
    img.Source = bi;

  • Get only published pages

    March 24, 2011 | Tags: EPiServer, Troubleshooting, Snippet
    Just getting the children for a page in EPiServer CMS 5/6 will return all pages, even unpublished ones. Since you might not want this behaviour there's a way to filter out all the published (or unpublished - if that's your cup of tea) using FilterPublished:

    using EPiServer.Filters;


    PageDataCollection myPages = GetChildren(myParentPage);
    new FilterPublished(PagePublishedStatus.Published).Filter(myPages);

  • Get LinkURL in page´s language and not current

    March 21, 2011 | Tags: EPiServer, Troubleshooting, Snippet
    This is a kind of weird thing about the LinkURL property of a PageData object in EPiServer. Even though the page in in a specific language, the LinkURL will ignore that and return a link to the current language version instead.

    If you want the URL to be in the same language as the page is, instead of:
    string url = page.LinkURL;
    ..start using AddLanguageSelection and pass the page´s language ID:
    string url = EPiServer.UriSupport.AddLanguageSelection(page.LinkURL, page.LanguageID);

  • Remove extra white-spaces within a string

    March 07, 2011 | Tags: C#, Regular expressions, Snippet
    Sometimes the trim function isn't enough. Say that you have a string looking like:
    "    this    is  a test     string   "

    Using Trim() would get rid of the extra white spaces in the beginning and the end, but it would still leave you with:
    "this    is  a test     string"

    So how to handle all extra white spaces, even those within the string? We'll lets use some regular expression for that:
    using System.Text.RegularExpressions;

    // Remove extra white-spaces within a string
    text = Regex.Replace(text, @"\s+", " ");

  • Time controlled publishing in EPiServer

    February 24, 2011 | Tags: EPiServer, Troubleshooting
    There's a neat way in EPiServer to time control publishing of pages. It's really easy when it comes to new pages, but when you want a new version of an existing page it turns out to be a little bit more rocket surgery.

    Here's how to do it:
    • Edit the page with your changes. Leave publish dates as is, you will set your date elsewhere.
    • Select "Save and view" (NOT PUBLISH!)
    • Two buttons are displayed, click "Ready for publish".
    • Goto the version list tab.
    • Last in the listing where your new version is there's a time schedule icons to the right. Click on it.
    • Tick the activate checkbox and enter time and date as you please.
    • Save and your new version of the page is now awaiting automatic publishing.

    Please note, that if you do another version of your page you'll need to go through these steps again.