Geeks With Blogs

Post Categories

Steve Land StrongEye Solutions LLC

MojoPortal is an open-source content management platform that we have started using at StrongEye because it offers an extensive out of the box starting point for ASP.NET Web applications, and also because it is incredibly developer-friendly.

UPDATE: For most common Web site tasks, you probably can go very far in MojoPortal without having to create custom code. These steps are advanced and for developers who want to create new functionality that cannot be accomplished with the existing feature set that comes out-of-the-box with MojoPortal.

One of the first tasks that a developer needs to do to get started with MojoPortal is to create a module. Basically a module is a starting point for a 100% custom application. The module is the shim that plugs in to MojoPortal proper, and allows you to include a entry point to your application in context of the portal.

I have found the documentation to be great on the MojoPortal site, but there are lots of small details that are hidden inside tutorial videos and elsewhere. This post is an attempt to bring all these things into one place so you can get started.

UPDATE: This post is updated to include a bit more context than before. Before you begin step 1, you must first have a local copy of MojoPortal loaded from SVN per instructions here (note: this links to Windows instructions as that is my bias, Linux SVN instructions are here).

Once you have all the Mojoportal source code loaded locally, you need to set up you VS Solution. The simplest way to do this is to copy an existing .sln file from the code you just got from SVN and rename it so that it will not be overwritten when you do new updates from SVN to get newer versions in the future.

For the purpose of this entry, I am going to make a copy of "mojoportal_mssql_only.sln" and I'll rename it 'mojoportal-localdev_mssql_only.sln'. Then I'll open this file in Visual Studio. Getting the initial project to run locally is beyond the scope of this article, though this is something that you must have working before any of the steps below will work.

How to create a MojoPortal module

Step 1: Create the 3 initial projects

 

 

Category

Steps

Notes

Create UI project

Create a new ASP.NET Web Application [yourProject].UI

 

Delete or rename the auto-generated Default.aspx file so it does not get copied to the portal by mistake.

 

Create subfolders in your Web project for your controls and asp.net pages:

/[yourProject]/

/[yourProject]/Controls/

 

Create a subfolder from the root of your Web project called "Setup:

/Setup/

 NOTE: don't create a new Web Site; what we want is a new Web Application.

 

Right click Solution root > 

Add > 

New Project > 

ASP.NET Web Application

 

Creating contents inside "Setup" is outside the scope of this article. See the developer documentation here for details on how to use the Setup system.

 

Create Business Layer project

Create a new Class Library project [yourProject].Business

 

Create Data Layer project

Create a new Class Library project [yourProject].Data

 

Rename your .Data project to [yourProject].Data.MSSQL (or whatever db you are using). By naming it .Data initially, Visual Studio sets the target assembly name to .Data, renaming the project does not cause this to change, which is the desired behavior.

All the .Data projects that are variants targeting different database technologies should all compile to the same assembly name so they can be swapped at build time.

Add References in your Web UI project

·         Log4net

·         mojoPortal.Business

·         mojoPortal.Business.WebHelpers

·         mojoPortal.Features.UI

·         mojoPortal.Net

·         mojoPortal.Web

·         mojoPortal.Web.Controls

·         mojoPortal.Web.Editor

·         mojoPortal.Web.Framework

·         [yourProject].Business

 

Add Reference in your [yourProject].Business project

·         [yourProject].Data.MSSQL

 

 

Add .resx file for localization

Create a standard ASP.NET folder App_GlobalResources.

In this folder, add a new .resx file by choosing Add > New Item > Resources file. Give the file a name matching your project name so that it is unique.

 

 

Step 2: Make your project mimic mojoPortal.Web enough that it will compile

 

Category

Steps

Notes

Update Web.Config

Open the Web.config file in mojoPortal.Web and copy the entire <pages> section in to your new [myProject].UI web.config

This section (<pages>) lives directly under <system.web> … your project may have an auto-generated section already. You can just overwrite the entire thing.

Copy Master Pages

Create a folder in your [myProject].UI project called “App_MasterPages”

Copy layout.Master from the WebStore.UI subfolder (this is preferable because it is a subset of the entire master page and it’s all that you need to develop). You can also simply copy the entire “App_MasterPages” folder from WebStore.UI (NOTE: NOT mojoPortal.Web! Important to use the folder from WebStore.UI instead!)

This gives your aspx pages the correct content placeholders when you develop your feature.

 

Step 3: Create your Module

The Module is an .ascx control that inherits from SiteModuleControl and creates the instance-specific entry point from the portal into your custom code. From this entry point, you may also have many other pages that are custom aspx pages that use the portal master page.

These steps rely on code generated by CodeSmith, which provides a free version on their site (here)

Category

Steps

Notes

Create Module ascx

In the folder created earlier in [yourProject].UI

/[yourProject]/

Right click and create a new Web User Control (.ascx) called

 [yourProject]Module.ascx

 

Generate ascx from CodeSmith template

Open CodeSmith Studio. In Template Explorer, open the folder “Codesmith4x” found in

\mojoportal\CodeSmith Templates\

 

Find the template called

Mp_UI-starter_ModuleControlGenerator.cst

Right click and choose “Execute”

 

A dialog will open prompting you for values. Here is what to choose:

 

Author: [your name]

BusinessLayerNameSpace: [yourProject].Business

ControlName: [yourModuleControlName]

FeatureName: [yourProject]

UINameSpace: [yourProject].UI

 

Click “Generate”

The result of the generated code includes both control UI code and code-behind c# code. You will need to highlight each section separately to cut and paste.

Cut and paste back into your Module

Select the code beginning with comments

// Author:   [yourname]

To the end. This is the code behind that goes in [yourModule]Module.ascx.cs

 

Open [yourModule]Module.ascx.cs and replace all the code with the copied code. Save.

 

Return to the generated Codesmith resulting code. In the .ascx source section, highlight ONLY the single line beginning with

<%@ Control … %>

Copy that and paste over the Source in your [yourModule]Module.ascx file. Save.

 

Copy the remaining code between

<%@ Control … %> and the code behind c# code comments from CodeSmith into your ascx source.

Save.

 

The sequence and steps are designed here to work around a Visual Studio problem in which the “TitleControl” is not found.

If you simply copy and paste everything all at once instead of following these steps, you may see the error:
“The name ‘TitleControl’ does not exist in the current context” even though the control is there. As long as these conditions are true, you should not see that message:

-          You have the proper MojoPortal references set

-          You have updated the <pages> section in Web.config

-          You copy and paste the CodeSmith output in the correct sequence and Save in between steps.

 

Step 3: Add post-build logic to your Web project

This step integrates your code with mojoPortal with each successful build, so you can run the code and see it in context.

 

 

Category

Steps

Notes

Open the Properties of your .UI project

Right click on [yourProject].UI in Visual Studio Solution Explorer, choose “Properties”. Navigate to the Build Events tab.

 

Add Post-build event command line instructions to your .UI project

The purpose of this section is so that your code from your UI project will be automatically copied into the mojoportal project with each build. If you haven't used these, $(ProjectDir) and $(SolutionDir) are macros that Visual Studio recognizes. For more info about post-build events,see this article.

Copy the commands below into the text box labeled “Post-build event command line:” and replace XXX with your project path names and YYY with your project names:

 

xcopy /s /y "$(ProjectDir)bin\YYY.UI.dll" "$(SolutionDir)Web\bin\"

xcopy /s /y "$(ProjectDir)bin\YYY.Business.dll" "$(SolutionDir)Web\bin\"

xcopy /s /y "$(ProjectDir)bin\YYY.Data.dll" "$(SolutionDir)Web\bin\"

xcopy /s /y "$(ProjectDir)XXX\*.ashx" "$(SolutionDir)Web\XXX\"

xcopy /s /y "$(ProjectDir)XXX\*.ascx" "$(SolutionDir)Web\XXX\"

xcopy /s /y "$(ProjectDir)XXX\*.aspx" "$(SolutionDir)Web\XXX\"

xcopy /s /y "$(ProjectDir)XXX\Controls\*.ascx" "$(SolutionDir)Web\XXX\Controls\"

xcopy /s /y "$(ProjectDir)App_GlobalResources\*.resx" "$(SolutionDir)Web\App_GlobalResources\"

xcopy /s /y "$(ProjectDir)Setup\*" "$(SolutionDir)Web\Setup"

 

Save after you have replaced the paths, right click your Web project and choose Properties. In the Build Events tab, click the Edit Post-build… button and you can paste this there.

Install your feature using the MojoPortal Administration tools

After you build your project, log in to MojoPortal as Administrator and navigate to this location:
Administration > Advanced Tools > Feature Installation / Configuration

You will see a list of all installed features, scroll down and click Add New Feature.

On the new page, enter your module entry point path in Control Source. You may also choose resource files, icons, and other options here. Click Update.

You may now add your new feature to a page.

 

 After the steps above are completed, with my project, here is my solution structure in Visual Studio:

 project structure

 

Posted on Wednesday, December 16, 2009 3:32 PM | Back to top


Comments on this post: Creating a MojoPortal module

# re: Creating a MojoPortal module
Requesting Gravatar...
I'm a newbie (and not familiar with C#!) so please forgive any stupid questions here.

I have found this really useful but, in spite of following it step by step, I can't overcome the problem with the TitleControl so I have commented out the code in order to get it to compile. Also, it would be helpful if you could post the folder tree for your projects so we can see where everything should be placed. I'm struggling to get the xcopy to work - I think it's because I've got my projects in separate folders and I haven't got the solution in the right one in relation to the projects.
Thanks for your assistance.
Left by Suzy Smith on Jan 06, 2010 3:23 AM

# re: Creating a MojoPortal module
Requesting Gravatar...
I just added some new detail to what the starting point of these steps should be, and I have verified that the TitleControl issue goes away if you do each step exactly as outlined (at leats in VS 2008). Please check the new updated article and see if that helps.
Left by Steve Land on Jan 06, 2010 1:55 PM

# re: Creating a MojoPortal module
Requesting Gravatar...
I also just added an image of the project structure, hope that helps. The TitleControl issue is a Visual Studio code generation error where the designer's generated code becomes out of synch. It's a frustrating error for sure. To fix the issue, try these steps:

In the .ascx file, select all but the first line and cut from your control. (leave the <%@ Control ... %> intact). Build, see errors. Then paste back what you just removed. Build again, errors disappear.
Left by Steve Land on Jan 06, 2010 4:20 PM

# re: Creating a MojoPortal module
Requesting Gravatar...
Thank you - really helpful. I have managed to get it all working - my challenge now is to do the same but in VB ...
Left by Suzy Smith on Jan 07, 2010 4:33 AM

# re: Creating a MojoPortal module
Requesting Gravatar...
Can you please share the codebase which should have a new feature?
Left by Ashish Verma on Feb 10, 2010 5:48 AM

# re: Creating a MojoPortal module
Requesting Gravatar...
Susy Smith - did you ever get a VB project to work in the MojoPortal solution?
Left by Frank Cowan on Feb 10, 2010 6:38 PM

# re: Creating a MojoPortal module
Requesting Gravatar...
I did get the overcome the TitleControl issue a little differently in C# and then I could get VB to work also. posted minor changes to your steps at mojoPortal forum
http://www.mojoportal.com/Forums/Thread.aspx?thread=4799&mid=34&pageid=5&ItemID=9&pagenumber=1#post20314
Left by Frank Cowan on Feb 13, 2010 7:55 PM

# re: Creating a MojoPortal module
Requesting Gravatar...
Hello. I am playing around with mojoPortal. I am using Visual Web Developer Express so i had to create 3 separate projects for this. I got what you have to work so far, now I need to make a Module.

In the xcopy section, should (SolutionDir) be my web directory? As in wwwroot\mojoPortal\?
Thanks.
Left by Mark Hudak on Mar 10, 2010 6:04 AM

# re: Creating a MojoPortal module
Requesting Gravatar...
Step 3 could use a little more "spelling out" for stupid developers as me
the post-build is a little comfusing
"Save after you have replaced the paths, right click your Web project and choose Properties"
is it [yourProject].ui or mojoportal.web you are talking about or is it just the same thing 2 times

the installing could also use some examples
Left by Martin on Mar 25, 2010 8:41 AM

# re: Creating a MojoPortal module
Requesting Gravatar...
I just updated the section on post-build, hopefully this is more clear. The quick answer is that it's [your project].ui.
Thanks for the feedback!
Left by Steve Land on Mar 25, 2010 9:03 AM

# re: Creating a MojoPortal module
Requesting Gravatar...
the problem with the post-build section is that you are telling people to choose Properties/ build events... 2 times one time before the xcopy and then again after xcopy
it was just that that confused me
Left by Martin on Mar 25, 2010 12:32 PM

# re: Creating a MojoPortal module
Requesting Gravatar...
Thanks for the article on post build stuff. Going to read it at lunch.

I had assumed as much, but just wanted to make sure.

Thanks again.
Left by Mark Hudak on Mar 26, 2010 6:56 AM

# re: Creating a MojoPortal module
Requesting Gravatar...
Hi,
Just a small query regarding mojoportal webparts :
Is it possible to communicate among different webparts added in a same page.

Thanks in advance,
Suvradeep
Left by Suvradeep Saha on Apr 06, 2010 3:55 AM

# re: Creating a MojoPortal module
Requesting Gravatar...
Modules are not web parts; the only area web parts are used is in the MyPage feature, to my knowledge. Modules can communicate together using session or similar means.
Left by Steve Land on Apr 06, 2010 9:23 AM

# re: Creating a MojoPortal module
Requesting Gravatar...
Steve,
Thanks a lot for your post. I am newbie to mojoportal.
What exactly the module in mojoportal refers to ? An example would be a great help.
I am inteded to populate a list of , say employees , in a page and on click of name of the employee it will open up another area , located in the same page , with the details of that employee. Should I develop a different page or some in built feature is available to handle this scenario.
Thanks in advance,
Suvradeep
Left by Suvradeep Saha on Apr 06, 2010 10:33 PM

# re: Creating a MojoPortal module
Requesting Gravatar...
Definitely, one of the best MojoPortal articles out there. Please, keep them coming!

Thanks
Left by Larry on Apr 23, 2010 5:12 AM

# re: Creating a MojoPortal module
Requesting Gravatar...
Thnks for great tutorial.
After that when next possible steps will come ?
Left by Mehmet KANPINAR on Jul 13, 2010 7:41 AM

# re: Creating a MojoPortal module
Requesting Gravatar...
Love your work. Thanks
Left by scott willis on Aug 02, 2010 4:40 PM

# re: Creating a MojoPortal module
Requesting Gravatar...
Thanks for that. I've spent endless hours trying to get my first webpage to the HelloWeb stage, and thanks to your tute, I've finally got there in less than 1 hour.
Left by MJO on Aug 20, 2010 5:37 AM

# re: Creating a MojoPortal module
Requesting Gravatar...
i have been trying to get my first module to work for two weeks and still no way foward. I can the The feature in the definition list but the Page does not show any text when a new page is created to use the feature. I am using vs2010 on windows7
Left by Yomi on Nov 30, 2010 3:56 AM

Your comment:
 (will show your gravatar)


Copyright © strongeye | Powered by: GeeksWithBlogs.net