Tuesday 17 August 2010

How to set up your N2CMS and Web Forms development environment

One of the areas I found a little tricky at first was to set up N2CMS so I could actually run it. I wasn't quite sure where to start, what batch files to run etc. This guide will help you download the N2CMS Web Forms Template software, set up Visual Studio with the snippets and get you running N2CMS with a SQLLite database.

This guide is purely to get you started. It's not going to get into any details, just a step by step guide to getting you ready to be able to follow some of my other guides later on.


Also, I am assuming you will be using Visual Studio 2008 as currently I believe there is issues with Visual Studio 2010.

First of all, go to www.n2cms.com and then go to the downloads page and download the "N2 CMS 2.0 ASP.NET WebForms Templates Pack" as highlighted here:-







Next, extract the archive out. I am going to extract this archive into my "d:\n2cms" folder. From now on, I will assume you will have done the same. You should now see something like this in your d:\n2cms folder:-



Because we're going to run this demo using SQL Lite, you will need to copy the two files in the "Libraries" folder into the N2CMS/bin folder. If it asks about copy and replacing, just click ok. If you don't do this, you will get an error when you try to run the site at the end of this guide!

Now, the next stage is to set up Visual Studio 2008 so that we can use the properties and page template options. I have found these invaluable when developing N2CMS sites and I'd strongly suggest you use them. To be honest, although setting up the properties isn't easy there's a couple of "gotchas" which are simple to miss. If you use these, it's just far, far easier to develop.

Ok, if you look inside the "Snippets" folder you'll see a few files that start with "n2" like


Copy these files into your "\Documents\Visual Studio 2008\Code Snippets\Visual C#\My Code Snippets" folder on your C: drive. When you develop a page in N2CMS, you'll be able to type "n2prop" then press tab and the code will be generated for you.

The next thing is to set up the page and item templates. In the "Snippets" folder there are two zip files that you need to copy to your "\Documents\Visual Studio 2008\Templates\ItemTemplates\Visual C#" folder:-


You can ignore the  "N2 Page Controllers" snippet as that is for the ASP.NET MVC project.

Right, now we've done the background work, go do d:\n2cms\n2cms and double click on the N2.Templates.sln file. Or you can open this from within Visual Studio 2008.




Once it's loaded you should see something like this now in your Solution Explorer:-




If you now press "Control and F5" together to run N2, you should then be able to see the N2 homepage!






Note: If you get an error saying "The IDbCommand and IDbConnection implementation in the assembly System.Data.SQLite could not be found." then you've forgotten to copy the MySQL files from the library folder. I nearly always do this when I start a new project!

10 comments:

  1. Nice post, I think this will be very helpful.

    ReplyDelete
  2. Hi JComet! Thanks for the comment - I am hoping to add an article a week!

    ReplyDelete
  3. Really helpful post, thanks!

    ReplyDelete
  4. Hello I am a php developer and I got a project to do in n2cms. Your tutorial helped me a lot...Thanks...

    I would like to know how to connect this to SQL server...It would be freat if you can help me.

    Thanks in advance

    Gops

    ReplyDelete
  5. Hi Gops

    If you look in the "web.config" file you'll see that there are several options already for you to use different databases under the "" section (the web.config file is just an XML document for configuring your application).

    What would would need to do is add the snippet below and then just change the values for your database server:-






    Let me know how you get on and happy N2ing!

    ReplyDelete
  6. I just got involve with this and this help me get started. Thx

    ReplyDelete
  7. This is the best tutorial. You've helped me a lot! Thank You.

    ReplyDelete