DotNetNuke 5 module development tutorial - part 2: Setting up the project

31. January 2010 23:05

To Visual Basic version

During the next parts of this tutorial we will create a module displaying a simple listing of products. We will call it... Products! In this part we will set up the project and look at what is in the templates.

In Visual Studio, create a new project. In the New Project dialog, select the Web project type. Then select "DotNetNuke Compiled Module" under "My Templates". Enter "Products" as the name of your module. Then point the location to the "DesktopModules" folder of your DNN installation. Make sure "Create directory for solution" is not checked. This is important. Click OK.

Visual Studio 2008 New Project dialog


Now when we have the project started, there are a couple of things you should know.
First: the project is kind of a cross-breed between a library project and a web project. This is so we can work with the user controls (the ascx files and their associated code-behind and designer files) pretty much like in a standard web project. If you just start an ordinary library project, add the files needed for a user control and try to work with them in the Visual Studio environment, you are neck deep in additional work.

Second: since the project is of the mixed type described above, it will try to run if you start debugging it. This will not work. I will cover dubugging of modules in a later post.

Third: If a web.config file for some reason is created in your module project; delete it. Since your project folder is a subdirectory in the DotNetNuke web application that hosts you module, a web.config file there will most probably lead to problems later on when you are running your web site.

With those things straightened out, go into the properties settings of your project by right-clicking the project node in solution explorer and selecting Properties in the context menu. On the Application tab to the left, set the Assembly name to "SipidCode.Modules.Products". Do the same with the Default namespace field.

Project settings screen

If you use Visual Studio 2010, you will get compilation errors:
"The type or namespace name 'DotNetNuke' could not be found (are you missing a using directive or an assembly reference?)". Thanks to Tim Haynes for pointing this out.
To solve this, set the project's target framework to 3.5 (instead of 2.0 as in the image above).

To make the designer work correctly with DotNetNuke controls we will have to help it find them. Select the Web tab to the left.
Check the radio button Use Local IIS Web server. Enter the URL to the folder where your module code is in your local DotNetNuke installation.
Make sure Override applicationroot URL checkbox is checked and enter the URL to your local DotNetNuke website under it.

Project web settings

You can now close the properties tab.
From the Edit menu, select Find and Replace > Replace in Files. Enter "YourCompany" in the Find what field, and "SipidCode" in Replace with. Expand Find options and make sure Look at these file types is set to "*.*". Click Replace All.

Visual Studio 2008 Find Replace window

You can now compile the project to make sure it works as it should.
Let's take a peek at what the project template has given us.

User controls: ViewProducts, EditProducts and Settings. These correspond to different modes of your module. Their names give us a hint of what they are for. The View control is used when the module is displayed to the visitors of your website. The Edit control is used when an administrator goes into edit mode. This is usually where the content of the module is handled. Then we have the Settings control. That one is displayed in bottom of the settings screen of the control. Used to handle settings special to your module.

Database setup and uninstall scripts: the files with the extension SqlDataProvider. As you see there is one with the version number "01.00.00". That one is run on installation of the module, setting up tables, stored procedures and so on. It's really just a SQL batch script. There can be multiple installation scripts, each corresponding to a version of your module. We will go into the details of that in some future post.
There is also the Uninstall script. That one is run on (yeah! you guessed right!) uninstallation of the module, removing the database objects created by the installation script.

Extension installation manifest: Products.dnn. This is the instruction file for the installation. It tells DotNetNuke stuff like which scripts to run, which files to copy where and so on. We will look closer at that one later on. We've got a lot of other stuff to cover before we get to the installation part.
Components folder. This is where the files involved in the data access layer are located.
The Documentation folder contains only some info concerning the project template. It is pretty obsolete and is of no interest to us.

Next time we are going to take a look into the data layer. Then we will write some code, at last.

Tags: , ,

DotNetNuke | Modules | Tutorials

Comments

3/16/2010 3:39:18 AM #

Ahui

wonderful! thanks a lot!

Ahui Singapore |

3/17/2010 8:56:47 PM #

Victor Maranhao

Hi,
A very well written and usefull tutorial!
I'm going step by step, I'm a dnn newbie, and your tutorial is helping me a lot.
I'm using Window/XP, IIS 6, VS 2008 express, SQL 2008 express and DNN 05.02.03 (74).
As I prefer to use VB, I'm translating the code.
At my first try to build your code the controls at ascx files cannot be refered by the code behind modules. This problem was solved leaving then "Root Namespace" text-box empty.

Thanks again,

Victor

Victor Maranhao Brazil |

3/17/2010 9:31:16 PM #

Johan

Great to hear you find it useful!
Thanks a lot for telling about your problem and how you solved it. It will hopefully help other VB coders encountering the same thing.
Happy coding!

Johan Sweden |

3/21/2010 8:57:20 PM #

emilio

thanks, i´m looking for something like that for a while. but in the best case my problem was that i cant view the ascx in desing time.
following these steps i manage it. so thanks again.

emilio Spain |

3/23/2010 6:56:38 PM #

Baychev

Johan,
You did great job. There is one thing that seems unclear to me: how do I register the module with DNN? I tried from Module Definitions >  Create Module From Manifest, but I am getting a postback with neither success nor error message. Without being registered, no installation pack can be created either.

Baychev United States |

3/23/2010 7:03:36 PM #

Baychev

Nevermind my question, the answer is in Part 3.

Baychev United States |

4/8/2010 10:04:45 PM #

Tim Haynes

Great series!  I have a problem following this step, though.  I have VS2010 RC, and DNN 5.2.3 CE (installed using the Microsoft Web Platform Installer), on Win2K3 R2.  When I follow the above steps and then try to compile, I get several dozen errors like this:

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

Any tips or hints you can give me?

Thanks!!

Tim Haynes Canada |

4/8/2010 10:32:38 PM #

Johan

Thanks for pointing this out! I don't have a solution to the problem at the moment. I will figure something out and post it here.

Johan Sweden |

4/8/2010 10:55:16 PM #

Johan

Try this:
In project properties, under the Application tab, set Target framework drop-down to ".NET Framework 3.5".

It would be great if you let me know if it worked or not.

Johan Sweden |

3/1/2012 10:43:00 PM #

Simcha

This doesn't solve the problem for me.
When I go to View.ascx and I type in the following:
<%=DotNetNuke. %>

VS2010 only offers DotNetNuke.Modules as an option.

Anyone found a solution to this or had the same problem?

Simcha United States |

4/9/2010 8:05:11 PM #

codeChowder

Thanks for this tutorial.  It’s very good!

One thing to note, if you nest your modules in a subdirectory DesktopModules/[Company Name]/[Module Name] then you have to ensure that the “Output path” under the “Build” tab of Project Properties is set to the DNN website bin.  Something like: ..\..\..\bin\

codeChowder Canada |

4/10/2010 11:19:24 AM #

Johan

Very good point.
Thank you for making this tutorial better!

Johan Sweden |

4/14/2010 1:45:27 PM #

Sotiris Filippidis

Excellent post, thank you! I've been having trouble with VS2008 losing the definitions in the designer.vb files and replacing them with whatever it thought it might be right. I had thought of something similar, but it's good to know that someone else has actually done it and it works!

Sotiris Filippidis Greece |

4/18/2010 11:02:02 PM #

trackback

DotNetNuke 5 module development tutorial - part 4: The view control

DotNetNuke 5 module development tutorial - part 4: The view control

Sipid Code |

5/18/2010 1:14:26 AM #

vga to svideo

Such a Good job on your blog. It is incredibly informative and to the point. I will be giving it 5 stars and enjoy reading additional within the future and hope you have a great day.

vga to svideo United States |

12/25/2010 12:33:02 PM #

Website design long Island

That 's great job dude ... and it is very ..nice

Website design long Island India |

12/29/2010 5:23:06 AM #

Ahad

Hi
I have this warning :

Missing XML comment for publicly visible type or member 'SipidCode.Modules.Products.ProductsInfo.ProductsInfo()'  D:\Projects\irdnn2\DesktopModules\Products\Components\ProductsInfo.cs  Products

What can i do ?

Ahad Iran |

1/31/2011 12:15:20 PM #

Steve Tanner

Really helpful tutorials. Thanks for posting them. There's a big lack of beginners info for dnn module development on the web and this kind of thing helps a lot.

Steve

Steve Tanner Switzerland |

2/3/2011 3:06:32 PM #

David

I am running our DNN on a separate development server, running IIS 7. It has FPSE extensions installed. Can you tell me how to configure my project to work in this dev environment?

David United States |

2/3/2011 3:07:04 PM #

David

Oh yeah - I'm running VS 2010

David United States |

4/26/2011 9:32:30 PM #

rdamian

Hi! I´m using VS 2010 and the StarterKit 5.06.01. I did everything like you said in this page but when I compile I get 4 errors, three of them are related to these lines of code inside the page_load method in the file EditProducts.ascx.cs:

  txtContent.Text = objProducts.Content;
  ctlAudit.CreatedByUser = objProducts.CreatedByUserName;
  ctlAudit.CreatedDate = objProducts.CreatedDate.ToString();


The error info for the first line is the following (the other errors r identical):
Error 8 'System.Web.UI.UserControl' does not contain a definition for 'Text' and no extension method 'Text' accepting a first argument of type 'System.Web.UI.UserControl' could be found (are you missing a using directive or an assembly reference?)

Is obvious that txtContext, which type is UserControl, doesn´t have a property called Text. I don´t know if I missed something. Could anyone help me with this?

rdamian |

4/26/2011 9:42:57 PM #

Johan

Take a look at my reply to the guy with a similar problem in part 5 (C# version). Hope you find some help there.

Johan Sweden |

4/26/2011 11:12:07 PM #

rdamian

Thank you Johan, I appreciate your help.

rdamian |

4/26/2011 11:16:43 PM #

Johan

Glad it worked out for you.
Happy coding!

Johan Sweden |

4/26/2011 10:02:29 PM #

rdamian

In order to continue with this tutorial I changed the following lines in the file EditProducts.ascx.designer.cs like this:

protected global::System.Web.UI.UserControl txtContent; for protected global:LaughingotNetNuke.UI.UserControls.TextEditor txtContent;

and
protected global::System.Web.UI.UserControl ctlAudit; for protected global:LaughingotNetNuke.UI.UserControls.ModuleAuditControl ctlAudit;

I don´t know if this is going to work but at least I can go on...

rdamian |

10/13/2011 11:51:11 PM #

Martin

I justwanted to add to this as I had compile errors. I found out when you search and replace YourCompany in VS 2010, it refactors the desinger files to use the standard System.Web.UI DLL files and not the DotNetNuke DLL. It looks like VS can't find the references when performing search and replace... who knows.

Martin Canada |

4/28/2011 5:23:56 PM #

Kim

Thanks for the comprehensive tutorial on developing modules in DNN5. I am using VS 2008 professional, and I am trying to set up my project. Everything works fine until I try to set the servers to use the IIS Web server. I set my Project URL to http://localhost/dnn5/DesktopModules/Product and I override the application root URL to http://localhost/dnn5/ and when I save the project properties, Visual Studio pops up a warning that says "The local IIS URL http://localhost/dnn5/DesktopModules/Product specified for Web project has not been configured. To keep these settings you need to configure the virtual directory. Would you like to create the virtual directory now?" If I say yes, the virtual directory is created but DNN 5 does not work after this. When I am logged in on the home page, I see the error "DotNetNuke.Services.Exceptions.ModuleLoadException: The file '/dnn5/DesktopModules/HTML/HtmlModule.ascx' does not exist. " When I am not logged in, no content appears on any page and the login controls will not display. Is this problem caused because I have my dnn5 installation in a virtual directory and not the root application? Thanks!

Kim United States |

5/2/2011 10:36:29 PM #

Johan

I usually host the DNN installations in web roots, but I am pretty sure I have used a virtual dir some time without problem. My suggestion is that you try to put it in the root and see if that works.
No other suggestions at the moment, unfortunately.

Johan Sweden |

5/18/2011 5:51:03 PM #

Peter

I had the same problem today, as I tried to do in the tutorial, but in my first trial, I forgot to set the correct project-path. So, it was configured in IIS as DesktopModules pointing to C:\...Dcouments\....
and failed in the second trial.

start inetmgr

Make sure, that in IIS you have the following:
DesktopModules is NOT a virtual directory
Your module DesktopModules\Products is a virtual directory pointing to
%yourdotnetnukeinstallation%\Desktopmodules\Products

Sorry for my bad english. If needed, I can provide screenshots, when email given.

Hope, this helps ;)

Peter Austria |

7/3/2011 8:51:46 AM #

pingback

Pingback from cynic.me

An Excellent DotNetNuke Tutorial | Cynic.me

cynic.me |

7/21/2011 5:24:17 AM #

David

Please note that if you are using a VS 2010 DNN 5 .NET 4.0 setup, that the framework should be set to use .NET 4.0.

David Australia |

8/12/2011 7:01:05 PM #

Ryan

I am having a similar issue. However it's strange that my problems only begin after I do the search and replace for 'YourCompany'. The company name is all one word and is very short so there is no issue there.

I'm using VS 2010 I've tried it with both v3.5 and v4.0 frameworks and everything compiles before I do that replace. So now I'm fighting with trying to get it to compile. I've tried rdamian's fix, and i get it to compile then. But if I make any changes to the EditProducts.ascx then VS rewrites the .designer.ascx and I'm back at square one.

I've also tried adding a control but they're asp:Label not dnn:Label to try and force the designer view but to no avail... I've also made sure that the module isn't in a virtual directory too.

I also get errors with:
<%@ Register TagPrefix="dnn" TagName="Label" Src="~/controls/LabelControl.ascx" %>
saying the file cannot be found

so I changed it to:
<%@ Register TagPrefix="dnn" TagName="Label" Src="../../controls/LabelControl.ascx" %>

However it still says "The file '~/controls/LabelControl.ascx' was not found." in the design view.

Ryan Canada |

8/17/2011 3:31:16 PM #

Ryan

I solved the issue. It was a IIS server configuration issue. Although I had added a new website and declared the root directory and disabled the 'Default Web Site' it was still looking at %SystemDrive%/inetpub/wwwroot. So I just moved everything there and it compiled fine.

Ryan Canada |

11/7/2011 10:27:08 PM #

Piotr

Hi,
I don't know why, but I have one issue while creating this project. I select the appropriate dnn module template, then put "Products" as a name and select "C:\inetpub\wwwroot\DotNetNuke\DesktopModules\" folder as a location and uncheck create directory for solution. I click OK and the error message pops up:

"Access to the path 'C:\inetpub\wwwroot\DotNetNuke\DesktopModules\Products\' is denied."

Can anyone give me a hint on what am I doing wrong?

Thanks in advance for your response.

Piotr United States |

11/24/2011 11:33:59 AM #

hongtat

Please set your Servers to "Use Local IIS Web Server" and it will solve the problem..

hongtat Malaysia |

1/26/2012 1:15:44 AM #

lee

Hy guys can someone help me :

I'm following instructions above, but at the end when I want to save changes that I made on a web tab there is a message: Web project has not been configured. To keep this settings you need to configure the virtual directory. Author of the text wasn't mentioning this, so I'm wondering what is it about?
any suggestions

lee United States |

3/5/2012 8:10:06 AM #

Jussy Smith

Really too good info.
You can also try http://www.daffodilsw.com/drupal-development for more...

Jussy Smith India |

5/11/2012 5:02:21 AM #

pingback

Pingback from duyanhpham.wordpress.com

HÆ°á»›ng dẫn viết module DNN 5 – DotNetNuke 5 module development tutorial  « Phạm Duy Anh

duyanhpham.wordpress.com |

Comments are closed

About the addict

Johan Seppäläinen lives in Uppsala, Sweden. He spends most of his days working as a systems architect/developer, specialized in solutions built on Microsoft platforms.
Occasionally there is time for some recreational coding, when he pursues optimal solutions and code zen, mainly in C#. When he is not writing in this blog, that is.