Search
| Login
corner corner
Relevant Links
corner corner
corner corner
Subscribe To Feed
corner corner
corner corner
Search Articles
corner corner
corner corner
Topics
corner corner
corner corner
Article List
corner corner
corner corner
Article Archive
corner corner
corner corner
Survey
Which platform does your company use?



Submit Survey  View Results
corner corner
corner corner
Relevant Links
corner corner
corner corner
Step-by-step Creating a DotNetNuke Module Using C#
Location: BlogsCubicZoneDotNetNuke    
Posted by: cubiczone 7/4/2007 8:04 AM

I'll show you how to create a simple DotNetNuke 4.x module using C#. Modules can be created with VB.NET also just as easily.

Requirements

You'll need a few tools before you can begin:

Adding New Item

On the Solution Explorer, right mouse on the root site and click on Add New Item.... 

DotNetNuke Module Creation Add New Item

You should now see a dialog box asking you to select the item to add. DotNetNuke allows you to build modules in either VB or C#. In this example, select C# as the preferred language. Give your module a name like "HelloWorld".

DotNetNuke Module Creation Add New Item Dialog

Adjust the Module Folders & Code

You'll quickly notice that the name of the module folder is always "ModuleName" even if I explicitly called it "HelloWorld" in the previous dialog. Visual Studio has limited capabilities to customize templates and this limitation is apparent in the screenshot below. You'll have to manually rename App_Code\ModuleName to App_Code\HelloWorld and DesktopModules\ModuleName to DesktopModules\HelloWorld before continuing. The files contained within the folder are named correctly and you don't need to modify those.

DotNetNuke Module Creation Add New Item ModuleName limitation

Since we're writing our module in C# and DotNetNuke core classes are written in VB, we need to compile our newly added module as a separate assembly. To do that we need to specify it in the web.config the code subdirectory. If you're writing in VB, you don't need to do this but it doesn't hurt to do it either.

<compilation>
        <codesubdirectories>
               <add directoryname="HelloWorld" />
       </codesubdirectories>
</compilation>

If you're using C# and running on DotNetNuke 4.5.3 Starter Kit, you may encounter some bugs when you try to run your web site. The author of the VSI templates forgot to translate some VB code to C#. It's normally not a big deal since the compiler will catch it and indicate on screen precisely where the bug occured. You just need to translate one or 2 lines back to C#.

For example the comment below:

' Use connection string specified in provider

should be rewritten to C# like:

// Use connection string specified in provider

Compile the solution and make sure you don't get any errors.

Install the DNN Manifest

You're now ready to install the module. From your web site, go to Host > Module Definitions page from the menu. On the top left corner of the title header, click on Create New Module.

DotNetNuke Module Creation Create New Module

The HelloWorld.dnn file contains all the information necesary such as location of files, version and name. Select the HelloWorld.dnn manifest file and click on Create new Module from selected Manifest file.

DotNetNuke Module Creation Create New from Manifest

Create Tables and Stored Procedures

To install the HelloWorld module to your web site, you'll need to create a custom table and several stored procedures that performs some simple insert, update and delete operations for the custom table. This is part of the simple HelloWorld functionality when you use the VSI template to create a module.  A simpler module, if created by hand, would not require any table or stored procedure at all. Since we want to make use of the VSI template, just open the DesktopModules\HelloWorld\01.00.00.SqlDataProvider file using notepad and copy the SQL content. Then from your web site, go to the Host > SQL page from the menu. Execute the SQL and check the Run as Script to tell the page to parse the SQL and replace any special DotNetNuke specific syntax.

DotNetNuke Module Creation Execute SQL

Add Module To Page

Congratulations! You've created your first module. You can now go to any page and add the HelloWorld on to that page.

DotNetNuke Module Creation Add Module 

The HelloWorld allows you to add, edit and configure settings for the module. Have fun !

DotNetNuke Module Creation View Module

Permalink |  Trackback

Comments (16)   Add Comment
Re: Step-by-step Creating a DotNetNuke Module Using C#    By Nixson on 11/15/2007 9:19 AM
Hai,

its really good, and worked perfectly.

I have one doubt.

This can be performed for applying a new item but what about for existing item.

I have created an application before and i have all the database connection,tables and stored procedure for that application.

Is it possible to add the existing item to Dotnetnuke?

If possible pls give me some idea.

watinging for your reply. my email id is n_nixson_n@yahoo.com

If possible pls send to my id

Thanks in advance

Nixson

Re: Step-by-step Creating a DotNetNuke Module Using C#    By Slim on 11/15/2007 3:18 PM
You should read this blog entry on what happens when a module is updated:

http://www.dotnetnuke.com/Default.aspx?tabid=825&EntryID=1246

Re: Step-by-step Creating a DotNetNuke Module Using C#    By Eric on 6/13/2008 1:48 AM
Very nice! Thank you. The little bug:



the "name" need to be "Name"

Re: Step-by-step Creating a DotNetNuke Module Using C#    By yasir on 8/29/2008 9:55 AM
nice tutorial

Re: Step-by-step Creating a DotNetNuke Module Using C#    By almny.com on 5/9/2009 7:18 AM
thanks you
i hope if you create skin by easy way like this

Re: Step-by-step Creating a DotNetNuke Module Using C#    By www.almny.com on 5/9/2009 5:43 PM
hi man
i have dnn ver 4.0
but after i click on Create New Module
i cant found this dropdownlist

Re: Step-by-step Creating a DotNetNuke Module Using C#    By slim on 5/11/2009 12:01 PM
>> I cant found this dropdownlist

Doublecheck your .dnn manifest file to make sure it's there on the DesktopModules\ folder and that the XML is correct.

very good guidline    By kishor pawar pune on 6/23/2009 11:15 AM
I really impress to this.

Thanks

Re: Step-by-step Creating a DotNetNuke Module Using C#    By umer on 7/6/2009 1:47 PM
i m gettin such error:
"The Auto option has been disabled as the DotNetNuke Application cannot connect to a valid SQL Server database. You can continue to use either of the other two Wizard options and configure the Database settings at the appropriate Wizard step."

why is it so?

Re: Step-by-step Creating a DotNetNuke Module Using C#    By Stephen on 7/6/2009 2:19 PM
Doublecheck the SQL connection in the web.config file. There should be two places where the connection string appears.

Re: Step-by-step Creating a DotNetNuke Module Using C#    By Cerber on 8/8/2009 5:03 PM
Hi.
I followed this article step by step and i finished it with success however the control i created is not visible on the page i added it.
Can you advise me in this matter?
Thank you

Re: Step-by-step Creating a DotNetNuke Module Using C#    By Slim on 8/10/2009 11:19 AM
Make sure you the Settings for the module instance has the proper permissions to display for All Users (even non-registered users)

Re: Step-by-step Creating a DotNetNuke Module Using C#    By good on 10/16/2009 5:56 AM
Goed!

Re: Step-by-step Creating a DotNetNuke Module Using C#    By Jamesdiaz on 12/6/2009 5:48 AM
I get ERRORS when I try to run the script:
Execute the SQL and check the Run as Script to tell the page to parse the SQL and replace any special DotNetNuke specific syntax.

You said REPLACE any special syntax ..... WHAT ??? give a bloody example
Please show more screen shots?




Re: Step-by-step Creating a DotNetNuke Module Using C# - Problem was in the sql script    By Jamesdiaz on 12/6/2009 2:51 PM
There are 2 sections in the file: Visual Studio 2008\WebSites\DotNetNuke Website1\DesktopModules\HelloWorld\01.00.00.SqlDataProvider

select ModuleId,
ItemId,
Content,
CreatedByUser,
{objectQualifier}$YourCompany$_$safeprojectname$.CreatedDate

Change Both these to:

select ModuleId,
ItemId,
Content,
CreatedByUser,
CreatedDate

Then run and it should create the following tables or procedures:

Name Owner Object type
YourCompany_HelloWorld dbo user table
YourCompany_AddHelloWorld dbo stored procedure
YourCompany_DeleteHelloWorld dbo stored procedure YourCompany_GetHelloWorld dbo stored procedure YourCompany_GetHelloWorlds dbo stored procedure YourCompany_UpdateHelloWorld dbo stored procedure
PK_YourCompany_HelloWorld dbo primary key cns
FK_YourCompany_HelloWorld_Modules dbo foreign key cns

You can check if these have been created by using the command:

SP_help without having 'run as script' checked

Re: Step-by-step Creating a DotNetNuke Module Using C#    By Sprnitiii on 2/18/2010 9:15 AM
Can you give me an advice, i have finished my module "Contact Us" but when i made Debug- Start Without Debaging i have two errors :

Error 1 YourCompany.Modules.ContactUs.ContactUsController' does not implement interface member 'DotNetNuke.Entities.Modules.IPortable.ImportModule(int, string, string, int)'
and
Error 2 'YourCompany.Modules.ContactUs.ContactUsController' does not implement interface member 'DotNetNuke.Entities.Modules.IPortable.ExportModule(int)'



Your name:
Title:
Comment:
Add Comment   Cancel 
corner corner