Thursday, July 31, 2008

Programmatically checking if the required alias is available in DotNetNuke

If you try to create a portal with a alias that in not available, DotNetNuke will complain about it and not allow you to continue ahead. It turns out that this duplication check is done by the UI and not the business layer. So if you are programmatically creating a portal, you will have check if the required alias is available, because the DotNetNuke API does not do it.

All the classes used below can be found in the assembly: DotNetNuke.dll in the DotNetNuke.Entities.Portals namespace

Listed below is some sample code you can use the following code you programmatically check if the required alias is available in DotNetNuke.

   1: public static bool IsAliasAvailable(string alias)
   2: {
   3:     //need to make sure that the alias does not contain http://
   4:     alias = alias.Replace(@"http://", "");
   6:     PortalAliasController aliasContoller = new PortalAliasController();
   7:     PortalAliasCollection aliasCollection = aliasContoller.GetPortalAliases();
   8:     return  !(aliasCollection.Contains(alias));
   9: }

Line 4: Since DotNetNuke does not store the "http://" part of the alias in its database, remove it from the string holding the alias before checking.
Line 7: Use the GetProtalAliases method in PortalAliasController class to get a PortalAliasCollection.
Line 8: Since PortalAliasCollection inherits from System.Collections.DictionaryBase, you can use the Contains method to check if the alias is available.


  1. Hi arjun

    are you able/willing to share the complete code for programmatically creating a portal? I'm trying to find a way to automate the creation of a portal from a template file


  2. Anonymous,
    Please check one of my earlier posts on how to create a portal programmatically:


Subscribe to my feed in your favorite feed reader