Setup

Follow the directions here to install the DotNetNuke Starter Kit and to create a DotNetNuke website.

Very important: Click once on the root directory in the Solution Explorer window. Doing so will ensure that the starter module code is created in the proper place.

Select File from the toolbar, then New File:

On the next menu, click once on DotNetNuke Module (under My Templates), select "Visual Basic" from the Language dropdown, type "GuestBook." in the Name box, and click Add.

I interrupt this tutorial for an important warning:

Note: If the files DataProvider.vb, GuestBookController.vb, GuestBookInfo.vb, and SqlDataProvider.vb in the "ModuleName" directory are under "DesktopModules/App_Code" then they are in the wrong place.

Click on the "ModuleName" folder and drag it under the "App_Code" directory that is directly under the main root of the website. You will also have to move the "DesktopModules/ModuleName" folder and drag the "ModuleName" folder so it is under the "DesktopModules" folder that is directly under the main root of the website.

This is the correct way it should look:

Now back to the tutorial:

A very helpful help page comes up and instructs you to rename /App_Code/ModuleName to /App_Code/GuestBook, and rename /DesktopModules/ModuleName to /DesktopModules/GuestBook.

Make the changes by right-clicking the folder name in the Solutions Explorer and selecting Rename from the menu. You have to do this twice. Once for the folder under "App_Code", and then for the folder under "DesktopModules".

Now, from the toolbar, select Build, then Build Web Site:

The website should build without errors.

In the Solution Explorer, right-click on "Default.aspx" and select Set As Start Page:

From the toolbar, select Debug, then Start Without Debugging.

(You may wonder why I am not covering debugging. While creating this tutorial, I ran into permission problems on my own machine. They are easily fixed but I wanted to avoid any unneeded complexity. If you need help debugging, see this post.)

The website should now come up.

Click Login:

Log in as "host". The password (if you haven't already changed it) is "dnnhost":

Click on the HOST menu and select SQL

The form will display.

Switch back to Visual Studio and in the Solution Explorer. Double-click on "01.00.00.SqlDataProvider" in the "DestopModules/GuestBook" directory so that it shows up in the main window.

Click once on the page, then from the toolbar select EDIT then SELECT ALL (Ctrl +A)

Then EDIT and COPY (Ctrl +C).

Switch back to the DotNetNuke website and paste (Ctrl +V) the script you copied into the window, click the "Run as Script" box and click EXECUTE.

From the HOST menu select "Module Definitions"

Click the small down arrow in the upper left hand corner of the Module Definitions menu and select "Create New Module"

Select "GuestBook.dnn" in the Module Manifest drop-down and click Install

Under the Page Functions menu, click Add:

In the Page Details menu:

Enter "Guest Book" for Page Name.

Enter "Guest Book" for Page Title.

Enter "Guest Book" for Description.

Click the View Page box next to All Users.

Then, click Update:

From the Module drop-down, select "GuestBook":

Then, click Add:

If you get the "Object reference not set to an instance of an object" error, just click on the "Guest Book" link:

(However, if you are running DotNetNuke on a machine that is lower than a Pentium III with 512 KB RAM, then DotNetNuke will regularly throw this error).

The module should now appear:

The Guest Book Module

We will walk through the construction of the Guest Book module in these steps:

Data Access Layer (DAL) - We will create the tables, the stored procedures, and alter code in the "SqlDataProvider.vb" and "DataProvider.vb" files.

Business Logic Layer (BLL) - We will alter code in the "GuestBookController.vb" and "GuestBookInfo.vb" files.

Presentation Layer (UI) - We will alter code in the "ViewGuestBook.ascx", and in the other files in the "DesktopModules/GuestBook" directory.

And that's it! It's actually not a lot of code to add to the "SqlDataProvider.vb" and "DataProvider.vb" files. Creating the tables and stored procedures is standard database programming that you are probably already used to.

Connect To The Database

If you have created your DotNetNuke website using SQL Server 2005 Express, your database connection should already be set up for you. If you set it up using SQL Server 2000 or SQL Server 2005, then you may have to set it up.

To set up a connection to the SQL Server database, from the toolbar, select View, then Server Explorer.

In the Server Explorer, right-click on Data Connections, and select "Add Connection":

Fill in the connection information, and click OK.

Delete the Sample Database Objects

You now need to delete the table and the stored procedures that the template created so that you can make new ones (that happen to use the same names) that the guestbook will use.

The connection will now show up in the Server Explorer. Click the plus next to the connection to expand it. Next, click the plus icon next to Tables to expand it.

Right click on the table "YourCompany_GuestBook" and select "Delete" and delete the table.

Note: At this point, the module will no longer work in your DotNetNuke web site. It will not work again until you have completed all the steps in this tutorial.

Click the plus icon next to Store Procedures to expand it. One at a time, right-click on the following stored procedures and select "Delete" to delete them. Remember, you have to delete them one at a time.

YourCompany_AddGuestBook

YourCompany_DeleteGuestBook

YourCompany_GetGuestBook

YourCompany_GetGuestBooks

YourCompany_UpdateGuestBook

Create The Table

Log into the DotNetNuke website as Host (if you are not already logged in as Host), and from the Host menu, select SQL.

Switch back to the "SqlDataprovider.vb" file and notice all the error messages are gone. Now would be a good time to save (Ctrl + Shift + S).

Review

Data Access Layer (DAL) (Done)

Business Logic Layer (BLL)

Presentation Layer (UI)

We are done with the Data Access Layer. We will now program the Business Logic Layer. The Business Logic Layer will get done fast because it is only two files: a simple class file to hold our data, and a "controller" file that will fill the class file with data as well as handle inserting and deleting data.

The Business Logic Layer (BLL)

To build the Business Logic Layer, we will:

Alter "GuestBookInfo.vb"

Alter "GuestBookController.vb"

And that's it! This is the step that is usually the hardest for beginners to understand but is really not that complicated. However, ASP.NET 2.0 does provide a major reduction of code over the ASP.NET 1.1 version.

Alter the "GuestBookInfo.vb" file

In Visual Studio, select View from the toolbar and the "Solution Explorer":

In the Solution Explorer window, expand the "GuestBook" directory under the "App_code" folder, and double-click on the "GuestBookInfo.vb" file:

Review

The "GuestBookInfo.vb" was created. This is just a simple class file. It will hold the data.

The "GuestBookController.vb" was created. This class has four methods:

GuestBook_Insert

Inserts items into the database. You pass a "GuestBookInfo" object to this method. The method then opens up the object and passes the individual parameters (module ID, name, email, message) to the "YourCompany_GuestBook_Insert" method in the DataProvider.vb file.

GuestBook_Delete

Deletes items from the database. You pass a "GuestBookInfo" object to this method. The method then opens up the object and passes the individual parameter (ID) to the "YourCompany_GuestBook_Delete" method in the DataProvider.vb file.

GuestBook_GetAll

Gets a recordset from the database. You pass a "ModuleId" parameter to this method. The method calls the "YourCompany_GuestBook_GetAll" method in the DataProvider.vb file and returns a "GuestBookInfo" object filled with data.

GuestBook_Update

Updates the database. You pass a "GuestBookInfo" object to this method. The method then opens up the object and passes the individual parameters (ID, module ID, name, email, message, date entered) to the "YourCompany_GuestBook_Update" method in the DataProvider.vb file.

A Lot Of Stuff Was Deleted

You may notice that a lot of code was deleted out of the "GuestBookController.vb" file. Some of this were the optional interfaces that handle exporting data and searching. These are interfaces that you will want to read about and implement in your modules. However, they are not required, and they are left out for simplicity.

A lot of code was eliminated by using code that is exclusive to ASP.NET 2.0 and incompatible with ASP.NET 1.1. ASP.NET 2.0 really saves you a lot of work and requires less code.

The Presentation Layer (UI)

From this point on, the files that need to be altered reside in the ".../DesktopModules/GuestBook" directory.

To build the Presentation Layer, we will:

Alter the "localization" (.resx) files.

Alter "controls" and their "code-behind" files:

EditGuestBook.ascx

Settings.ascx

ViewGuestBook.ascx

And that's it! The module will then be complete.

Alter the Localization Files

Localization allows you to create labels that can have their text changed (for example, to change text from English to Spanish) by simply changing a "resource" file that has a ".resx" extension.

Double click on "EditGuestBook.ascx.resx" to open it.

Change the content so it matches the picture below. The order does not matter. Save and close the file when done.

Double click on "Settings.ascx.resx" to open it.

Change the content so it matches the picture below. The order does not matter. Save and close the file when done.

Double click on "ViewGuestBook.ascx.resx" to open it.

Change the content so it matches the picture below. The order does not matter. Save and close the file when done.

Alter the Controls

The module consists of three controls (and their "code-behind" files):

EditGuestBook.ascx

EditGuestBook.ascx.vb

Settings.ascx

Settings.ascx.vb

ViewGuestBook.ascx

ViewGuestBook.ascx.vb

(A screen shot from the module definition that was created in the DotNetNuke site in the early step of the tutorial.)

Right-click on "EditGuestBook.ascx" and select "View Markup":

Replace all the code with this code (save and close the file when done):

I tried but its not working..... i have go through many blogs and etc but failed..... i need some good links... my site is www.mybooklover.com now its says Access to the path 'G:\PleskVhosts\mybooklover.com\httpdocs\DotNetNuke.log4net.config' is denied.

here am using New Version of Dotnetnuke(7.4) and am in frame work 4.0 which is Dotnet 2010. when i was try to create a new file i didnt see the template for DNN CMS..

i can able to create menus, pages in cms. but i need to customize the banners and some contents form backend.. how can i do it.. simply i have an html files then i need to convert that html pages as dotnet pages using DNN CMS..

I am new to DNN. I'm trying to learn how to use DNN Modules, but I can't seem to get away with it.

I installed DNN using the 06.01.02 starter kit. I work with Visual Studio 2010.

Everything worked at first, I created my portal, added a couple of pages, and customized them no problem, until I tried to add the new module. I called id "ConsultarMarcajes".

I was following your article, and errors started appearing once I had already added the module and got to the point "Rename "YourCompany" if desired". The article tells us to compile the project to make sure everything is OK... and I guess it was not in my case. When I compile my project, I get a lot of error messages saying:

"The type or namespace name '[X]' could not be found (are you missing a using directive or an assembly reference?)"

Where [X] is always "ConsultarMarcajesInfo", "ConsultarMarcajesController" or "DataProvider".

When the new module was added, a few filed where added to a folder named \PortalEmpleado\Portals\0\DesktopModules\ConsultarMarcajes: ConsultarMarcajes.dnn, ViewConsultarMarcajes.ascx, EditConsultarMarcajes.ascx, etc. and the following files containing classes were copied to PortalEmpleado\Portals\0\App_Code\ConsultarMarcajes: ConsultarMarcajesController.cs, ConsultarMarcajesInfo.cs, DataProvider.cs and SqlDataProvider.cs.

I guess, from the classes defined in \PortalEmpleado\Portals\0\DesktopModules\ConsultarMarcajes, I cannot access the classes defined in PortalEmpleado\Portals\0\App_Code\ConsultarMarcajes. Is there any reason for that?

The new namespace, after renaming the initial "Philip" namespace which VS2010 created by default, is "PortalEmpleado.Modules.ConsultarMarcajes". I checked all files belong to this same namespace.

SQLSQLUpload a file into the SQL Query window (Optional). SQL File:Upload a file into the SQL Query window (Optional). LoadSelect the Connection String you wish to use ( loaded from the list in the web.config file ) Connection:Select the Connection String you wish to use ( loaded from the list in the web.config file )

hi friendsin my ViewBookBuy.ascx page this error occur:'Context' is not member of 'Isattis.Modules.BookBuy.ViewBookBuy'my company name is "Isattis" and i changed all of "myCompany" string to "Isattis",in top of viewGuestBook.ascx i used this directive: