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.

Tuesday, July 1, 2008

Programmatically creating DotNetNuke portals - Part 1

If the need ever arises you can use C# to use the DotNetNuke API to programmatically create portals you can use the code listed below. Of course the code will need all the right permissions to do this. You will need the following information to create the portal.

  1. Portal Name
  2. Administrator first name and last name
  3. Administrator username and password
  4. Administrator email
  5. Portal description
  6. Portal Keywords
  7. Name (including path) of the template to the applied to the portal
  8. Portal Alias
  9. Server path (the path to the root of the Application)
  10. If it is a child portal the child path (the path to the child portal folder)

Listed below are the required steps to create the portal and perform some essential house keeping activities:

  1. Make sure that the alias does not contain the string "http://".
  2. Check if the required alias is available.
  3. Encrypt the administrator password with the machine encryption key.
  4. Get all the required paths: template path, home directory and server path.
  5. Create the portal.
  6. Add the new http alias (url) to the Http handler.
  7. Log the portal creation event tp DotNetNuke's event log.

In the next few days, I'll add a detailed post for each of the steps listed above.

Update 1: I've just posted an article on Programmatically checking if the required alias is available in DotNetNuke

Update 2: I've just posted an article on Programmatically creating DotNetNuke user passwords

Subscribe to my feed in your favorite feed reader