A few weeks back I blogged about wanting to create a module that would simply output the contents of an html file. After watching Will Morgenweck video on how to create a simple one page module in DotNetNuke 5.5 – an awesome feature by the way – I had the idea to do the same thing for the HtmlDirect module. It should be a simple enough module, and it can be done in a single page. So here we go:
This is the workflow I want to use when editing this static html content to be included in my portal:
1. Open my favorite html editor
2. Create a new html file and write some cool / mean / clean html code
3. Reference some special css and js files if I want to
4. Upload it to my site
5. Add the html direct module, point it to the file and that’s it.
Editing is now simply opening the html file, editing it and republishing it. Rinse and repeat
Overview:
1. Create a new module through the DNN interface
2. Edit the View.ascx file that gets created automatically, to render the file named in the module settings
3. Create an editor to edit the fileName module setting. This must be done in the same page. So I’ll show it when the module is editable, and hide it when it is not.
Here is a video that shows the process, and you can download the source packaged module bellow.
Code:
1: <%@ Control Language="C#" Inherits="DotNetNuke.Entities.Modules.PortalModuleBase" %>
2: <%@ Import Namespace="System.IO" %>
3: <%@ Import Namespace="DotNetNuke.Entities.Modules" %>
4:
5: <script runat="server">
6:
7: protected void Page_Load(object sender, EventArgs e)
8: {
9: // Render the file
10: RenderFile((string)Settings["fileName"]);
11:
12: // Show the editor
13: if (IsEditable && !IsPostBack)
14: {
15: fileNameDiv.Visible = true;
16: fileName.Text = (string)Settings["fileName"];
17: }
18: }
19:
20: // Render the html file
21: private void RenderFile(string renderFileName)
22: {
23: try
24: {
25: if (!string.IsNullOrEmpty(renderFileName))
26: {
27: // Strip off the initial slash if any
28: if (renderFileName.StartsWith("/") || renderFileName.StartsWith("\\"))
29: renderFileName = renderFileName.Substring(1);
30:
31: // convert into a physical path
32: renderFileName = "~/portals/" + PortalId + "/" + renderFileName;
33:
34: // render the text of the file
35: fileContent.Text = File.OpenText(Server.MapPath(renderFileName)).ReadToEnd();
36: }
37: }
38: catch (Exception ex)
39: {
40: fileContent.Text = (IsEditable) ? ex.ToString() : "Error displaying module content. Unable to find file!";
41: }
42: }
43:
44:
45: // This changes the rendered file to a new file and saves in the module settings
46: private void SaveFileNameButton_Click(object sender, EventArgs e)
47: {
48: ModuleController objModules = new ModuleController();
49: objModules.UpdateTabModuleSetting(TabModuleId, "fileName", fileName.Text);
50: RenderFile(fileName.Text);
51: }
52:
53: </script>
54:
55:
56: <%--Edit the file name--%>
57: <div runat="server" id="fileNameDiv" visible="false">
58: File Name <br />
59: (i.e. HomePageFiles/Content.htm where "HomePageFiles" is a folder at the root of the portal): <br />
60: <asp:TextBox runat="server" ID="fileName" width="100%"></asp:TextBox> <br />
61: <asp:Button runat="server" ID="saveFileNameButton" Text="Save File" OnClick="SaveFileNameButton_Click" /> <br />
62: <br /><br />
63: </div>
64:
65:
66: <%--Placeholder for the html content--%>
67: <asp:Literal runat="server" ID="fileContent"></asp:Literal>
68:
69:





Posted by kanika on January 31, 2013 at 9:37 pm
Hi,
I recently tested your module. But when I add a custom html file (which has the use of a dropdown list) using this module it changes my main menu also.