Showing posts with label EPiServer. Show all posts
Showing posts with label EPiServer. Show all posts

2017-09-11

Adding nicer icons to the PageTree in EPiServer

I did some research about adding nicer icons for pages in the EPiServer Page Tree, and I came up with some nice resources.

What seems to be common for all approaches is that you must create css-classes that encapsule each icon to use. At the moment I don't see how to get around this without actually creating the classes.

You also need to create an InitializableModule which sets up the icons when the web is started. I have omitted that code here. Please read the example from the first example below (from blog.nansen.com), for that code.

This example is complete and shows how to use your own (or a third party lib) icons:
http://blog.nansen.com/2014/10/page-tree-icons-in-episerver-cms-75.html

This example shows how to create your own icons (as an image sprite) and use for the icons: https://jonika.nu/JonasBlogg/archives/347


Here's one that shows how to use the already included icons from EPiServer:
https://ericceric.ghost.io/use-episervers-content-icons-as-site-tree-icons/

In stead of creating and maintaining the list of Episerver icons yourself, as in the example above, you could go for the Jon D Jones nuget package: https://www.nuget.org/packages/JonDJones.IconPack/. This iconpack does not really contain any icons, just convenience constants that point to the built-in episerver icons (it seems so to me anyway).


I created a generic attribute, based on reflection, that plugs in the JonDJones icon pack (download from Nuget, as mentioned) into the first example I mentioned from the "nansenblog":

[AttributeUsage(AttributeTargets.Class)]
public class ContentIconAttribute : Attribute
{
    public ContentIconAttribute(Type type, string propertyName)
    {
        IconClass = GetStaticStringValueFromLib(type, propertyName);
    }

    private string GetStaticStringValueFromLib(Type libType, string name)
    {
        var fieldInfo = libType.GetField(name);
        var propInfo = libType.GetProperty(name);
        var value = (fieldInfo?.GetValue(null) ?? propInfo?.GetValue(null)) as string;
        return value;
    }

    /// 
    /// Css class to apply to the icon
    /// 
    public string IconClass { get; set; }
}

And here's how to use it:
using JonDJones.IconPack;

[ContentIcon(typeof(ObjectIcons), nameof(ObjectIcons.Start))]
public class StartPageModel : BasePage
{
    ...
}

2010-02-16

Experiences on upgrading EPiServer 4.51 to 4.62B part 2

Ok, so the upgrade has been done, but will the project compile?

Sadly the answer is no.

I got the exact same problems described here: http://world.episerver.com/templates/forum/pages/thread.aspx?id=19575&epslanguage=en. It took some time for me to understand the answer to the part they did give an answer to. They didn’t answer the second question at all.

Problem 1: WsrpHelper doesn’t exist any more

My solution, which saves me from having to go through 8-10 places and correct the code, was to create a new class inside the WsrpPortal.aspx.cs file:

class WsrpHelper
{
    public static IConsumerEnvironment ConsumerEnvironment
    {
        get { return ElektroPost.Wsrp.Consumer.ConsumerContext.ConsumerEnvironment; }
        set { ElektroPost.Wsrp.Consumer.ConsumerContext.ConsumerEnvironment = value; }
    }

    public static void EnsureConsumerEnvironment()
    {
        if (ElektroPost.Wsrp.Consumer.ConsumerContext.ConsumerEnvironment == null)
        {
            ElektroPost.Wsrp.Consumer.ConsumerContext.ConsumerEnvironment = ConsumerFactory.ConsumerEnvironmentInstance();
        }
    }
}

Problem 2: LanguageManager.GetContextLanguage() is obsolete

It says in the error message that you should use LanguageContext.Current as a replacement, but that would create a type conversion exception.

I am guessing that you can to use LanguageContext.Current.CurrentUILanguageID as a replacement for GetContextLanguage() (please do correct me if I’m wrong).

DISCLAIMER:
I haven’t been able to test my solution, since the webs I am working on don’t actually use the portal framework. My code compiles now, so the web is up and running, and I am happy for the time being. If anyone finds any flaw in my solutions please don’t hesistate to leave a comment.

2010-02-15

The EPiServer Offline Package is a ZIP-file

So if you for instance need to just upgrade the database, not the whole EPiServer installation, you can just rename the offline upgrade package from .pkg to .zip, and you will find all the files used by the upgrade wizard inside.

Ypou can create an offline upgrade package from and to the versions you want using the EPiServer Manager, as mentioned in my previous post.

The database scripts are located in the “Upgrade” folder, and if you sort them ascending by name and run them in that order, you should be able to upgrade the database “manually”.

Scenarios where this method may be used may be

  • you did/tested the upgrade in your development environment and then deployed the upgraded files
  • you have already upgraded EPiServer on a staging server and the production database (which is an earlier version) should be restored on the staging server

The EPiServer Manager does other things than just copying files, like registering components in the GAC, so use the EPiServer Manager whenever possible. Also, remember to always have nescessary backups available.

2010-02-12

Experiences from upgrading EPiServer from version 4.51 to 4.62B

Ok, so previously I have upgraded my project files and solutions from Visual Studio 2003 to 2008, and have upgraded to master pages. I wrote about this in an earlier post: http://stgaup.blogspot.com/2010/02/upgrading-episerver-to-masterpages.html.

So now the next step. Upgrading the EPiServer version from 4.51 to 4.62B.

Since I am going to upgrade at least 2 sites, and someone in IT Operations needs to do the same upgrade on the production systems, I thought it would be a good idea to create an offline install. I had to google a bit and eventually fond out that to create an offline package, you need to:

  1. Start EPiServer Manager
  2. On the Tools menu, select “Create offline installation…”
  3. Click Next
  4. Select “Upgrade”
  5. Select From version in my case 4.51)
  6. Select To Version (4.62B)
  7. Specify directory where the package should be created.
  8. Click “Create”.

I had no problems with this part of the job.

Next I had to do the upgrade:

  1. Backup all files and the EPiServer database.
  2. Right-click the web site to upgrade in the EPiServer Manager, and select “Upgrade…”.
  3. Click Next.
  4. Select “Offline” and then browse to the package created before.
  5. Click Next.
  6. Review upgrade info, then click “Upgrade”.

The next thing happening was that the upgrade was being done, and the progress bar was showing some progress, until about 20% on the way. Then I got an error message: “Failed to register ASP.NET client scripts on this site”

It turns out that the EPiServer Manager is not able to install when there are versions of the .NET Framework installed after version 2.0. So the dirty trick you need to do is to remove the 3.0 and 3.5 folders from the WINDOWS\Microsoft .NET\Framework folder because EPiServer Manager will try to locate aspnet_regiis.exe (and maybe other command line utilities) in those folders, and it’s not there. This thread was helpful: http://world.episerver.com/Templates/Forum/Pages/Thread.aspx?id=17376&epslanguage=en.

Ok, so after I had moved those folders, it seemed that the upgrade worked, until I tried to browse the web:

EPiServer 4.62.0.533 can only be used with database version 100, current version is 90. Make sure both database and assemblies are upgraded correctly.

I didn’t get any errors while upgrading. Everything seemed to go well, but it didn’t. The EPiServer Manager failed to upgrade the database.

I am assuming at this point that the database upgrade failed because the web was using Windows Integrated security with SQL Server. I thought it could work because I had made sure that my windows user account had owner rights to the database, but sadly it failed.

Tip: Don’t use Windows Integrated Security with EPiServer (when upgrading) even though Microsoft recommends that as the most secure way of accessing SQL Server. If you do, you will (probably) need to set up your site with impersonation, and turn off anonymous access.

Ok, so then I tried to run the upgrade once more after setting a SQL Server username/password. I then got the message:

The site is already up to date (4.62.0.533) – no new versions available.

So now time for my next dirty trick, one that I have used before, which is to copy the old EPiServer.dll back into the bin folder of the web site. (Of course I had a backup.)

So new upgrade attempt. First had to restart the EPiServer Manager, because it still thoght the web was version 4.62B. After restarting it said 4.51, as I intended it to.

This time the upgrade worked as it should, and the web is up and runnig again, now og EPiServer 4.62B.

IMPORTANT: Copy back the .NET 3.0 and 3.5 Framwork files to their correct location!

NEXT STEP: Upgrade to CMS 5? Am I brave enough?

2010-02-05

Upgrading EPiServer to MasterPages

Initial Status:
I have already upgraded the EPiServer solution from Visual Studio 2003 / .NET 1.1 to Visual Studio 2008 / .NET 2.0/3.5. First upgraded to VS2005/.NET 2.0 by opening the projects in VS2005 and using the wizard, then converting the project to a web application. Then did the same again, opening the project in VS 2008. Everything seemed to work fine after the upgrade. So next step is to upgrade from using EPiServer:DefaultFramework to using master pages.

Next steps:
I found the (very good I might add) article: http://world.episerver.com/Articles/Items/Experiences-from-migrating-to-EPiServer-461-and-ASPNET-20/ and tried to follow the steps described from the section called “Upgrading your custom templates to ASP.NET 2.0”. However there seems to be some little information missing:

  1. In addition to changing the <@ Control … to <@ Master … you must also in code-behind change the inheritance so that the master page inherits from System.Web.UI.MasterPage in stead of EPiServer.WebControls.ContentFramework.
    This will cause some problems:
    1. If you have any references to CurrentPage, you will need to fix it. I fixed it by creating a new property on the master page called CurrentPage:

      public PageData CurrentPage
      {
          get
          {
              PageBase pb = (PageBase)this.Page;
              return pb.CurrentPage;
          }
      }

    2. Also if you are using any commands that are not prefixed and are using functionality from the previous base class you will need to fix them:
      1. Translate(…) => EPiServer.Global.EPLang.Translate(…)
        I solved this by creating a private function in the master page code-behind, which saved me from changing code in multiple places:
      2. private string Translate(string key)
        {
            return EPiServer.Global.EPLang.Translate(key);
        }

      3. GetPage(…) => EPiServer.Global.EPDataFactory.GetPage(…)
        Again I solved it by creating a private function with the same name:
      4. private PageData GetPage(PageReference pageLink)
        {
            return EPiServer.Global.EPDataFactory.GetPage(pageLink);
        }

  2. The process of converting from the 1.1 style of declaring the controls in code-behind to the 2.0 way using the .designer.cs file is not always working as is should. I had to go into the code-behind file and remove declarations of controls, and then made a slight change to the front master page file, and the saved it, so that the controls using the runat=”server” attribute were (automatically) declared in the designer.cs file. Also some events vere explicitly declared in code-behind (opposed to the new way of using “AutoEventWireup=True”. I just removed them as they were doing nothing anyway.

  3. Also had a small problem due to some additions to the asp.net control gallery and poor naming conventions. The old EPiServer Content Framework files declared a conrtol called simply “Menu”. This name crashes with the “System.Web.UI.WebControls.Menu” web control, so I just changed the name.

And now my web is up and running with EPiServer 4.51 (on VS2008) and using Master Pages (on only one page so far: default.aspx). After changing all aspx-web forms so that they use the new master page, the next step will be to upgrade EPiServer to 4.62B, and thanks to the previously linked article this should hopefully be a piece of cake.

2009-12-16

Check if any new properties have been added in EPiServer 4.x

The scenario for this is that you have a Test server and a Production server. You are rolling out all changes that have been tested on the Test server to the Production server. You did, being a pro and all, of course make a note of all the changes that were done to properties on the Test server since the last rollout to Production, but just to make sure you want to check what new properties have been added.

Step 1

Add the Production server as a linked server in SQL Server Management Studio on the Test server, in this example called [LinkedServer].

Step 2

Create a new query on the Test server and paste the following query into it. You will need to substitute the names of the database and linked server with names from your environment.

-- CHECKS IF ANY NEW FIELDS HAVE BEEN ADDED ON THE TEST SERVER
-- THAT DO NOT EXIST ON THE PRODUCTION SERVER
USE EPiServerDb;
GO

IF EXISTS(
    SELECT testTable.pkID, prodTable.pkID
    FROM tblPageDefinition testTable
    LEFT JOIN [LinkedServer].[EPiServerDb].[dbo].[tblPageDefinition] prodTable 
        ON testTable.pkID = prodTable.pkID
    WHERE prodTable.pkID IS NULL)
BEGIN
    PRINT 'NEW PAGE PROPERTIES DETECTED!'
    SELECT pt.Name, pd.Name
    FROM tblPageType pt JOIN tblPageDefinition pd ON pt.pkID = pd.fkPageTypeID
    WHERE pd.pkID IN (
    SELECT testTable.pkID
    FROM tblPageDefinition testTable
    LEFT JOIN [LinkedServer].[EPiServerDb].[dbo].[tblPageDefinition] prodTable 
        ON testTable.pkID = prodTable.pkID
    WHERE prodTable.pkID IS NULL)
END
ELSE BEGIN
    PRINT 'NO NEW PROPERTIES DETECTED.'
END

Step 3

If any new properties have been added, you will see a list of the names of page templates and what properties are new.

This script was tested on EPiServer 4.61/62 only, but may also work for newer versions of EPiServer.

2009-10-02

Styles missing in EPiServer Edit/Admin mode

If you ever experience this, it’s probably because EPiServer uses a custom remapping for the 404 – Page Not Found error in IIS. To fix it do the following:

  1. Open IIS manager, and right click on the web site.
  2. Select “Properties” from the dropdown menu.
  3. On the “Custom Errors” tab, scroll down the list until you see “404” in the HTTP Error column.
  4. Double click the 404 entry to open the properties box.
  5. Set the Message type to “URL”.
  6. Type “/util/NotFound.aspx” in the URL text box.
  7. Click “OK”.
  8. Click “OK” in the web site properties dialog to close it.
  9. That’s it, now Bob’s your Uncle!

2009-09-21

EPiServer declines to support XForms on IE8 for CMS 4.x

According to this thread http://world.episerver.com/Forum/Pages/Thread.aspx?id=28931&epslanguage=en it seems that EPiServer is denying responsibility to make XForms on EPiServer 4.x work with IE8 since IE8 was released after EPiServer 4.x.

The customers are experiencing an error when loading XForms with radiobuttons and/or checkboxes. The error is “invalid form” (translated from the Norwegian “ugyldig skjema”).

UPDATE 2011-01-17: Also I have experienced that in IE8, the submit button will not submit the xform which is strange, since it should be calling a javascript function: “return(false)”, and then specifying an action string.

In the comments to this posting, Björn Sållarp has proposed a solution from his blog: http://blog.sallarp.com/episerver-xforms-ie8/

2008-06-10

Javascript error in EPiServer admin mode ('Invalid argument')

In this posting, Mark Bagnall describes a problem with javascript in EPiServer Edit Mode. I had the same problem. It was not possible to expand any branches in the EditTree, and the web browser reported a javascript error. Turned out I had set up my website in IIS with Windows Authentication only, to enable debugging/stepping in Visual Studio. The problem was fixed by allowing "Anonymous" access.