Thursday, May 3, 2012

Visual Studio SharePoint Solution Structure

One of the key things that needs to be sorted out in the initial phase of a project is to design the solution structure. A well thought through solution structure will enable good scale-ability and flexibility to future enhancements / changes to the solution.

Visual studio by default provides a number of solution templates for SharePoint 2010. However, many a times, these do not fit in properly when there are a number of elements / features in the solution. The following is the approach that have proven to be very useful. This approach can be taken as a base approach and can be modified to suit individual needs.

The first thing that needs to be ironed out is the names schema for the folders, projects, files. For this example,
Folders:  .
Project: .Sharepoint.

Web provisioning project (XYZ.Sharepoint.Provisioning) :
This project is responsible for getting the gathering all the project deliverable in a single location and preparing for packaging of the solution. The SharePoint project consist of multiple WSPs and other artifacts. Gathering them manually from their respective folders gives a lot of room for errors (picking old files, omissions etc). This project will build the entire solution, copy all the deliverable from the respective locations and move them to a single location.


Site Structure: This project will contain all the site definitions, templates, themes, master pages etc.


Presentation, Business and Data 
The traditional 3 layer approach with separate project for Presentation, Business and data project. It is recommended to group the projects on a logical level. i.e all web parts related to a particular module should be grouped together to form a single project.

Folder Structure: The visual studio logical folder is a excellent method to organised the solution. All the similar elements should be grouped together in folders so that the solution can be easily understood by the developers. The folders are logical folders and visual studio does not create physical folder to replicate the same.

XYZ Third Party Tools: This contains the third party tools used. In case of open source tools, the code base for the same is kept here so that the source is available for enhancement in future

XYZ Tools: This folder maintains all the standalone custom tool developed for the application.

XYZ Test: This folder contains all the automated unit test projects built for the solution

Friday, February 12, 2010

Installing MOSS on a single server machine

This blog forms a guideline for Installing MOSS on a single server machine .
Many a times, developer start off on a moss project on a pre built MOSS VPC image. This saves a lot of time and the developer can jump start and be productive. One main drawback of the VPC is that, it is real slow to work on and many a case, it can be a real pain to work with. This is when i decided to pump up my desktop and make this as a Single server MOSS box that really responds to my clicks :)

My first installation was performed on my gut feel and was not really the optimal installation. So I had to reinstall the box again. And this led me to write this blog. So that my mistakes could actually help someone to not make them.

Now what all are the pre requisites for the MOSS installation
  • Install Windows Server 2003 /2008
  • Install SQL Server 2005 (Optional)
  • Install Microsoft Office  (Optional)
Install Windows Server 2003 /2008
  • I stongly recomend to install MOSS on a clean machine. I ran into trouble when i was reinstalling the MOSS after uninstalling a previous attempt. The Reinstallation sometimes fails to create the content database properly. And thus will lead to many more issues later.

          2003 instructions
          2008 instructions 
  • Ensure that all the updates / patches / hot fixes for the OS are run after installation.
  • Install the Antivirus. You would not want to see all your effort go down the drain, would you?
  • If you are installing this in your office environment, you would like to join this server to the domain. In my case, i created a domain on the server. Click here for instruction on how to create a domain
  • Create a new Active Directory (AD) account. This account ( Service Account ) will be used for all MOSS installation purpose. This account requires the local Admin rights.
  • Install IIS
  • Install .NET framework 2.0 as well as 3.0

Install SQL Server 2005
  • Log in as the service account created in last step.
  • Install the SQL Server 2005 / 2008
  • 2005 instructions : http://msdn.microsoft.com/en-us/library/ms143516(SQL.90).aspx
  • 2008 instructions : http://msdn.microsoft.com/en-us/library/ms143219.aspx
  • Install SQL Sever Management Studio (Optional)
  • Add the service account to the Service Administrator and Database Creator roles.
  • Run the windows update and install all the updates for the SQL Server.


Now we are ready to install MOSS.
Get the installation CD, A cup of tea and a book ( Calvin and Hobbes will be a good option )
Login as the Service Account created.
Open start menu > Run > InetMgr
Ensure that 'ASP.net V2.0.50727' web service extension is allowed in IIS. If this is not allowed then perform a 'repair' on .net 3.0 framework using add/remove programs.Web service extension will now appear in the list.
Insert the MOSS CD and run Setup.exe
Enter the CD Key when prompted
Choose the Advanced Option for the installation. The basic option will install basic version of SQL Server and will not utilise the SQL Server that we installed earlier.
Select the Complete installation option in the next prompt ( Server type ) and then click on Install.
Once the installation runs to completion, it will pop up a screen with the option "Run the SharePoint products and Technologies Wizard now". Check this option and finish the installation.
After the installation, the MOSS wizard will jump up on the screen.
A warning message stating that many of the services will be restarted will be popped. Click on Yes.
An option to configue the farm will be promped. Select 'No , I want to create a new farm' option.
Provide the database server (your server name) and your account details (Note: the Account should be entered in domain\user format). Leave the database name as the default. Click 'Next'.
Leave the authentication mode as 'NTLM', set a specific port number is desired (not required) and click 'Next'.
You'll get a summary screen; click 'Next' and now sit back and sip the tea. if it still not complete, i now suggest you to start on the book that you picked up.

NOTE: if the setup fails, check the application log. It would mostly be due to the issues in creating content database. Check the SQL Server installation / Service Account permissions.

You'll get a success screen at the end, click 'Finish'.

The Wizard will now open up the Central Admin. Your Server is ready to be productive.

There are a set of configurations that are to be completed on the server. The MOSS portal will work even without these configurations. But to utilize the full potential of the MOSS, it is recomended that these steps also to be completed. I will be posting on those steps in my next blog

Monday, February 1, 2010

Improve MOSS Performance


Sharepoint/ MOSS is a resource intensive application. And this is exactly the reason why the sharepoint / MOSS developer needs to be extra cautious on the performance implication of the code that they spin out.
Here is some pointers to areas where the processing power is drained out.  A little caution here and there can increase the performance of the application significantly.

During the development phase, the developers may not notice the impact of the performance to the full extent. However, once the application moves to production and data accumulates over the time, then the same lines of codes will start taking more and more time to execute.

Check for memory Leaks 
Most Sharepoint developers will know that they have to dispose the SPSite object. But why doesn’t the garbage collector treat them also like any other variable?
The SPSite and the SPWeb object are created as managed property.  So ideally they should be disposed properly. However, they internally use large amount of unmanaged data. This will not get disposed properly. In general, any object that uses the IDisposable object in MOSS should be disposed properly.

The most common coding method used is as follows
using(SPSite mySite = new SPSite(http://server:portno)
{
using (SPWeb myWeb=mySite.open())
{
//My code
}
}

Word of Caution:
1.       Do not use this method when getting hold of the context web (SPControl.GetContextWeb(HttpContext.Current) because this will refer to current context and when the code moves out of scope, it will try to close the current context object.
2.       Another major pit fall is the below code
       using (SPWeb web = new SPSite(SPContext.Current.Web.Url).OpenWeb())

this will dispose the web object created. But the new spsite object will not be disposed and will take the precious memory.

BOOST Performance of the Code
1.       SPWeb.Lists(“MyList”)
This is a expensive method. It will load all the list metadata un the spweb and then string compares all the title and retrieve the required list.
Instead use SPWeb object to retrieve list using the url of the list
Web.getList(“http://site/list/allitem.aspx”);
This will make considerable resource saving when there is a large number of lists in the web object
2.       Iterating the list item
Another common performance drainer that I have come across.
For(id=0; item in list;id++)
{
Variable = list.items[id].fieldname;
}
This will create a item collection each time it loops. Imagine the number of collection it needs to create for a large list!! Simply initializing the item collection outside the loop will gain a lot of performance in this case.
3.       Retrieving the list item count
List.Items.Count method will retrieve all the items in the list and then count it. A huge list means huge resource wastage. Instead of this method, use list.ItemsCount method. ItemsCount is part of the list metadata. That means that you already have this information in memory and don’t have to burn any more cpu cycles to get this.
4.       Retrieving list items using itemQuery
Query is a better way to retrieve the list items than simply opening the list item object. This can be further optimized by setting item limit to the retrieval. Smaller the batches that is retrieved, lesser the load on machine.
5.       Getting list item by GUID
SPList.items[GUID / Int32] or SPList.Items.GetItembyID(Int32)
This will retrieve all the items in the list to the memory and then search for the required item. Instead use the below syntax
SPList.GetItemByUniqueID(GUID)/SPList.GetItemByID(Int32)