Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Adding Modules to a Page with CodeAdding Modules to a Page with Code
Previous
 
Next
New Post
6/15/2009 6:25 PM
 

I have written a converter to migrate for school off our old CMS onto DotNetNuke.  For that I am programmatically creating pages and adding Text/HTML and Effority Workflow modules.  Thanks to some nice tutorials by Kemmis things are looking pretty good, however I have a bug that I can't figure out.  After a new page and module are programatically created everything looks great but clicking Settings on the module causes an exception.  I've looked at the database even using SQL Profiler and I can't figure out what is missing.

 
Has anyone had success adding modules from code?  Below is the Kemmis article and the exception.  I appreciate any ideas.  I am stuck:
 
http://www.kemmis.info/blog/archive/2007/11/20/how-to-programmatically-add-and-remove-modules-from-dotnetnuke-pages.aspx 
 
Error: Module is currently unavailable.
DotNetNuke.Services.Exceptions.ModuleLoadException: Object reference not set to an instance of an object. ---> System.NullReferenceException: Object reference not set to an instance of an object. at DotNetNuke.Modules.Admin.Modules.ModuleSettingsPage.BindData() at DotNetNuke.Modules.Admin.Modules.ModuleSettingsPage.Page_Load(Object sender, EventArgs e) --- End of inner exception stack trace ---
 
 

-something clever or funny.
 
New Post
6/29/2009 4:00 PM
 

FYI I solved this problem.  Talk about a needle in a haystack.  Maybe I would have saved some time if I had debugged from the DNN source.

In the end it came down to the difference between a lowercase and uppercase L.  In my code I was calling the AddNewModule procedure that I had stolen from ControlPanel.vb to create my module and passing in "Left" for the align parameter.  That call did NOT throw and error.  However later when I looked at settings for my new module from the page I got an exception.  It turns out that the settings code was choking on "Left".  Once I changed the database value to "left" then it was fine.  I had found my needle.

For those looking to repeat my sucess and not my failure.  Here are the basic steps to add a new module to a page programmatically.  Note that in my case I was adding an effority module.  Also the original AddNewModule procedure adds to the ActiveTab, so you I just moved the module to the tab I wanted

Dim objModules As ModuleController = New ModuleController()
Dim modInfo As ModuleInfo
Dim modInfoNew As ModuleInfo

' Get the DesktopModule and then use it to add the module to a page
modInfo = objModules.GetModuleByDefinition(PortalSettings.PortalId, "effority.WF_HTML")
AddNewModule(sTitle, modInfo.DesktopModuleID, "ContentPane", 0, ViewPermissionType.View, "left")

' Find the module that was added
Dim dicModules As Dictionary(Of Integer, ModuleInfo) = objModules.GetTabModules(PortalSettings.ActiveTab.TabID)
For Each kvp As KeyValuePair(Of Integer, ModuleInfo) In dicModules
  modInfoNew = kvp.Value
  If (sTitle = modInfoNew.ModuleTitle) And (modInfoNew.PaneName = "ContentPane") Then
    Exit For
  End If
Next

' Move the module from the current Tab to a new tab.  Note objCopyToTab is a TabInfo object representing my new tab.
' I created that new tab by following the instructions on the two articles I cited above.
objModules.MoveModule(modInfoNew.ModuleID, PortalSettings.ActiveTab.TabID, objCopyToTab.TabID, "ContentPane")


-something clever or funny.
 
New Post
7/27/2009 4:49 AM
 

Hi Mark

I'm wondering if you can help me. I am also trying to add modules programatically. I am extending the IWebCS module, so that I can call a Web Service Method and add a new page.

I am wanting to programatically add a new page with the HTML module, and populate the module. I have the code working that adds the page, but I am having trouble with adding the module.

If possible, could you please explain how I would add the HTML module?

I have looked at ControlPanelBase but I still cannot see how I can add and populate the HTML module - its very confusing.

Any help would be greatly appreciated.

Thanks and regards,

 
New Post
7/27/2009 7:44 AM
 

I can see that I create an instance of DotNetNuke.Entities.Modules.ModuleInfo

and create an instance of DotNetNuke.Entities.Modules.ModuleController

and then call AddModule(moduleInfo);

However, I also see that if I want to add a HTML module, I should probably use an instance of DotNetNuke.Modules.HTML.HtmlTextInfo, populate the various properties etc. But then how do I add this?

Thanks

 
New Post
7/28/2009 6:03 AM
 

Ok if anyone can help with this it would be greatly appreciated.

 

Here is my code. I can add a page programatically, but the module is not getting added to the page - and I cant figure out why.

 

[

WebMethod(Description = "Creates a new page")]public int CreatePage(string pageName, string content, string lang)TabController controller = new DotNetNuke.Entities.Tabs.TabController();TabInfo newTab = new DotNetNuke.Entities.Tabs.TabInfo();false;false;true;false;"";"";//newTab.ParentId = int.Parse(

 

// ParentsDropDownList.SelectedValue);

 

//newTab.TabPermissions = PermGrid.Permissions;

 

int newTabId = controller.AddTab(newTab); //add new page.

 

// clear cache

 

 

 

DataCache.ClearModuleCache(newTab.TabID);///Add module to newTab

DotNetNuke.Entities.Modules.

DotNetNuke.Entities.Modules.

modInfo.DisplayTitle =

modInfo.Header =

 

ModuleInfo modInfo = new DotNetNuke.Entities.Modules.ModuleInfo();ModuleController mc = new DotNetNuke.Entities.Modules.ModuleController();true;"header string";//modInfo.IsDefaultModule = true;//do we need this?

modInfo.Alignment =

modInfo.TabID = newTabId;

 

"ContentPane";//modInfo.DesktopModuleID = 68; //HTML text module

modInfo.ModuleID = 68;

modInfo.PortalID = 0;

modInfo.EndDate = System.

modInfo.InheritViewPermissions =

modInfo.IsDefaultModule =

modInfo.ModuleOrder = 1;

 

modInfo.PaneName =

 

 

DateTime.Now.AddYears(10);true;true;"ContentPane";int newModule=mc.AddModule(modInfo); //add module to the page

 

//DotNetNuke.Modules.HTML.HtmlTextInfo htmlInfo = new DotNetNuke.Modules.HTML.HtmlTextInfo();

 

//DotNetNuke.Modules.HTML.HtmlTextController htc = new DotNetNuke.Modules.HTML.HtmlTextController();

 

//htmlInfo.Content = "this <b>is</b> the content";

 

//htmlInfo.Approved = true;

 

//htmlInfo.DisplayName ="display name";

 

 

 

 

//DotNetNuke.Entities.Modules.DesktopModuleController dmc = new DotNetNuke.Entities.Modules.DesktopModuleController();

 

//DotNetNuke.Entities.Modules.DesktopModuleInfo dmi = new DotNetNuke.Entities.Modules.DesktopModuleInfo();

 

 

 

 

// modInfo = mc.GetModuleByDefinition(PortalSettings.PortalId, "Text/HTML");

 

// DotNetNuke.UI.ControlPanels

 

 

//(objTab, sTitle, modInfo.DesktopModuleID, "ContentPane", 0, ViewPermissionType.View, "Left");

 

 

 

 

 

}

return newTabId;

 

 

{

 

DotNetNuke.Entities.Tabs.

DotNetNuke.Entities.Tabs.

newTab.PortalID = 0;

newTab.TabName = pageName;

newTab.Title = pageName;

newTab.Description = pageName;

newTab.KeyWords = pageName;

newTab.IsDeleted =

newTab.IsSuperTab =

newTab.IsVisible =

newTab.DisableLink =

newTab.IconFile =

newTab.Url =

 

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Adding Modules to a Page with CodeAdding Modules to a Page with Code


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out