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

HomeHomeDevelopment and...Development and...Getting StartedGetting StartedCreating pages and adding module to the pages Creating pages and adding module to the pages
New Post
10/1/2014 6:56 AM


I am using DNN 07.03.02 and i created a module to create pages and add modules to the pages. Now i can successfully add pages and modules but i have an issue with Admin Control bar it is not working on the pages created programmatically.

Could you help me in solving the issue. I am pasting my code below

 protected void btnImport_Click(object sender, EventArgs e)




                //Get the files from the Directory

                string[] docs = Directory.GetFiles(txtFilePath.Text);

                //Loop all the files

                for (int i = 0; i <= docs.Length - 1; i++)


                    // Get the filename

                    String tabName = Path.GetFileNameWithoutExtension(docs[i]).ToUpper().ToString();

                    PortalSettings portalSettings = new PortalSettings();

                    int portalId = portalSettings.PortalId;

                    string defaultPortalSkin = portalSettings.DefaultPortalSkin;

                    string defaultPortalContainer = portalSettings.DefaultPortalContainer;

                    TabController tabController = new TabController();


                    //TabInfo parentTab = tabController.GetTabByName("HOME", portalId);


                    //if (parentTab != null)



                        TabInfo tab = new TabInfo();

                        tab.PortalID = portalId;

                        tab.TabName = tabName;

                        tab.Title = tabName;

                        tab.Description = tabName;

                        tab.KeyWords = tabName;

                        tab.IsVisible = true;

                        tab.DisableLink = false;

                        tab.IconFile = "";

                        //tab.ParentId = NULL;

                        tab.IsDeleted = false;                        

                        tab.Url = "";

                        //tab.SkinSrc = defaultPortalSkin;

                        //tab.ContainerSrc = defaultPortalContainer;

                        tab.IsSuperTab = false;



                        //Add permission to the page so that all users can view it

                        foreach (PermissionInfo p in PermissionController.GetPermissionsByTab())


                            if (p.PermissionKey == "VIEW")


                                TabPermissionInfo tpi = new TabPermissionInfo();

                                tpi.PermissionID = p.PermissionID;

                                tpi.PermissionKey = p.PermissionKey;

                                tpi.PermissionName = p.PermissionName;

                                tpi.AllowAccess = true;

                                tpi.RoleID = -1; //ID of all users

                                tpi.RoleName = "All Users";

                                tpi.PermissionCode = "SYSTEM_TAB";





                        int tabId = tabController.AddTab(tab, false);                        



                        DesktopModuleInfo desktopModuleInfo = null;

                        //Add a module to the newly created page/tab

                        foreach (KeyValuePair<int, DesktopModuleInfo> kvp in DesktopModuleController.GetDesktopModules(portalId))


                            DesktopModuleInfo mod = kvp.Value;

                            if (mod != null)

                                if (mod.FriendlyName.IndexOf("HTML") > -1 || mod.ModuleName.IndexOf("HTML") > -1)


                                    desktopModuleInfo = mod;





                        if (desktopModuleInfo != null)


                            foreach (ModuleDefinitionInfo moduleDefinitionInfo in ModuleDefinitionController.GetModuleDefinitionsByDesktopModuleID(74).Values)


                                ModuleInfo moduleInfo = new ModuleInfo();

                                moduleInfo.PortalID = portalId;

                                moduleInfo.TabID = tabId;

                                moduleInfo.ModuleOrder = 1;

                                moduleInfo.ModuleTitle = Path.GetFileNameWithoutExtension(docs[i].ToString());

                                moduleInfo.PaneName = "ContentPane";

                                moduleInfo.ModuleDefID = 116; //moduleDefinitionInfo.ModuleDefID;

                                moduleInfo.CacheTime = 0; // moduleDefinitionInfo.DefaultCacheTime;

                                moduleInfo.InheritViewPermissions = true;

                                moduleInfo.AllTabs = false;

                                moduleInfo.Alignment = "";

                                moduleInfo.DisplayPrint = false;

                                moduleInfo.IsShareable = true;

                                moduleInfo.IsShareableViewOnly = true;



                                ModuleController moduleController = new ModuleController();

                                int moduleId = moduleController.AddModule(moduleInfo);


                                //creating the content object, and adding the content to the module

                                HtmlTextController htmlTextController = new HtmlTextController();

                                WorkflowStateController workflowStateController = new WorkflowStateController();


                                int workflowId = htmlTextController.GetWorkflow(moduleId, tabId, portalId).Value;


                                HtmlTextInfo htmlContent = htmlTextController.GetTopHtmlText(moduleId, false, workflowId);

                                if (htmlContent == null)


                                    htmlContent = new HtmlTextInfo();

                                    htmlContent.ItemID = -1;

                                    htmlContent.StateID = workflowStateController.GetFirstWorkflowStateID(workflowId);

                                    htmlContent.WorkflowID = workflowId;

                                    htmlContent.ModuleID = moduleId;

                                    htmlContent.IsPublished = true;

                                    htmlContent.Approved = true;

                                    htmlContent.IsActive = true;



                                htmlContent.Content = getAllText(File.ReadAllText(docs[i].ToString()));


                                int draftStateId = workflowStateController.GetFirstWorkflowStateID(workflowId);

                                int nextWorkflowStateId = workflowStateController.GetNextWorkflowStateID(workflowId, htmlContent.StateID);

                                int publishedStateId = workflowStateController.GetLastWorkflowStateID(workflowId);


                                htmlTextController.UpdateHtmlText(htmlContent, htmlTextController.GetMaximumVersionHistory(portalId));





               // }


            catch (Exception ex)





HomeHomeDevelopment and...Development and...Getting StartedGetting StartedCreating pages and adding module to the pages Creating pages and adding module to the pages

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