Hi,
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)
{
try
{
//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";
tab.TabPermissions.Add(tpi,true);
}
}
int tabId = tabController.AddTab(tab, false);
DataCache.ClearModuleCache(tabId);
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;
break;
}
}
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)
{
Response.Write(ex);
}
}