Blog posts

  • 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.

  • Sync user and login for SQL database

    February 01, 2011 | Tags: Frax, Database, Troubleshooting, SQL, Snippet
    Got a login on your SQL server and the same user in a database but they are not connected? Even though the names are the sames the unique IDs are not. Here's a snippet from my college Fredrik that's very useful connecting the user name between server login and database user. Replace 'user' with 'your user name':
    EXEC sp_change_users_login 'Auto_Fix', 'user'

    And a small celebration! This is the 100th post :)