SharePoint Farm Solution Project Structure

Introduction

Creating a new SharePoint Farm Solution is itself a challenge where we need to align the resources to the right place to make sure your code is rightly placed and maintainable for longer run. Here we have come up with a SharePoint Farm solution structure considering all the possible SharePoint module developments in mind. Please find the below image for more details.

project
Fig. SharePoint Farm Solution project Structure


For SharePoint Solution project name keep the standard guideline of ClientName.SharePoint.ModuleName e.g. xxxxxxxx.SharePoint.ProjectName. In case you have any client specified governance we urge you to use the same with client guidelines in mind.

As Shown in image above we have categorized project in mainly section mentioned below:

  1. Infrastructure:

    This section covers all the infrastructure related modules for your SharePoint application to function correctly;  it includes Site Columns, List Definitions, Content Types, and Custom Actions etc.

  2. Layouts:

    This is SharePoint 15 hive mapped folder; where we will keep all the Application pages, Fonts, Images (not SharePoint Mapped folder), Master Pages, Scripts, and Styles etc.

  3. Providers:

    This section will cover all the core SharePoint Application logic covering business, Data access, and presentation layer of the module.

  4. Individual components:

    This section will cover all the individual components like Event Receiver, Timer Jobs, Web parts, Resources, Controltemplates etc.

Let’s cover each of these sections.

  1. Infrastructure :

    This is the folder where all the SharePoint application infrastructure related modules will reside. This includes Site Columns, Lists, Content Types, Custom Actions, and External Content Types etc.

    1.1 Site Columns: This folder will contain a Site Columns module with Element.xml file containing definition for site columns.

    columns

    Make sure your site column definition will include all this field attributes. See below field definition.

    code

    Here Name and StaticName corresponds to internal name of the field and it should match to maintain its consistency around the application.

    1.2 Lists: This folder will contain a list required for SharePoint application to function as expected. Add module as shown in below image.

    list

    A basic list item in SharePoint solution will look like this

    solution

    Make sure you have fulfilled each of its section as shown below:

    section
                                                       Fig. Showing the list of Columns

    view
                                  Fig. List all the views and its column sequence in settings

    list
                   Fig. Define list Title, URL, Description and additional list settings

    1.3 Content Type: This folder will contain a list of content types used across the application. Add module shown below and define its base type either item/document.

    Content

    When we will add a content type make sure you setup additional settings like Content Type Title, description etc. See below image for more information.

    type
                                  Fig. Showing CT Name, Description etc. settings


    1.4 Custom Actions: Add custom actions of the application in this folder. Add below module.

    Actions

    Make sure you add appropriate comments associated with Custom Actions so that anyone can understand which action is doing what. See below image.

    code

  2. Layouts:

    This is a SharePoint 15 hive mapped folder; add it. Follow and create a folder structure as shown in image above.

    2.1 Fonts: Consider a case where you are developing an intranet portal which is using different fonts for different areas of the portal. Add all the list of fonts in this folder.

    2.2 MasterPages: Add a list of Masterpages in this folder. To add a master page to your SharePoint Solution. Add a module as shown below :

    MasterPages

    When you will add the same; a file with Sample.txt will be added. Simply replace the .txt with .master.

    Sample

    Now; open your SharePoint Site in SharePoint Designer and copy Seattle.master code and paste the same in Sample.master.

    2.3 Pages: This folder will contain a list of application pages; if project requires feel free to add one or two level of folder depending upon your need to maintain a list of application pages. Add below shown module.

    Pages

    Things to remember:

    2.3.1 Whenever you will add a new application page make sure you replace DynamicMasterPageFile attribute by MasterPageFile pointing to correct master page.

    2.3.2 Make sure your master page is containing all the ContentPlaceHolders present in your Application page.

    2.3.3 Make sure you have setup the appropriate value for Page title attribute for your application page.

    code

    2.3.4 All the custom Styles and Scripts which are applicable for your application page should be a part of your page only and not of your master page.

    2.3.5 Use SharePoint:ScriptLink tag to register scripts file.

    2.3.6 Use SharePoint:CssLink tag to register styles file.

    2.4 Scripts: This folder will contain a list of .js files. Add below module for the same.

    Scripts

    2.5 Styles: This folder will contain a list of style sheets .css files

    Styles

    2.6 Images: This folder will contain a list of images used in application.

  3. Providers:

    This is a place where your core logic of the application resides. Here we have identified some list of folders which will covers most of the project code base however if needed add your own identified set of folder as per requirements or remove those which are not applicable.

    3.1 CacheManager:

    This folder will contain a class file named CacheManager.cs; it will define all the methods used to set/get cache data related to application. HTTP Caching will be used to store and retrieve data. Following methods will be defined:

    SetCache:

    This is a public method will be used to set the cache data against the particular key passed. Method signature:

    public static void SetCache<T>(string key, T item)

    GetCache : This is a public method will be used to get the cached data depending upon key passed. Method signature:

    public static object GetCache(string key)

    Note: If your project require you to use any third party logging dls continue to use the same.

    3.2 ExceptionManager:

    This folder will contain a class file named ExceptionManager.cs; it will define all methods used to log exception data related to application. If you are using any third party logging dlls please add it in separate class library.

    3.3 Entities:

    This folder will contain a list of .cs class files maintaining the entities used in an application.

    Add a module as shown below.

    Entities

    For e.g. Employee entity – Employee.cs
    1. public int DepartmentId { getset; }  
    2. public int EmployeeId { getset; }  
    3. public string FirstName { getset; }  
    4. public string LastName { getset; }  
    5. public string MiddleNameName { getset; }  
    6. public string Designantion { getset; }  
    7. public string EnterpriseId { getset; }  
    8. public string EmailId { getset; }  
    3.4 Constants:

    This folder will contain a list of .cs files maintaining a list of constants used across application. Add a module as shown below.

    Constants

    3.5 Extensions:

    This folder will contain a list of extension method used across application SPExtension.cs file.

    3.6 Utilities:

    This folder will contain a list of helper methods defined in Helper.cs file and so on.

    3.7 DataAccess:

    This folder will contain actual data operation where we will be doing the data access operations for application.
    Add a class files as per needs and write the data access logic here.

    3.8 BusinessLogic:

    This folder will contain an actual business logic or flow of the application. All the business layer operations will be a part of this folder.

  4. Individual Components:

    4.1 TimerJobs:
    This folder will contain a list of timer jobs if your application has any.

    4.2 EventReceivers: This folder will contain a list of event receivers if your application has any.

    4.3 ControlTemplates: This folder will contain a list of user controls if your application has any. This is a SharePoint 15 hive mapped folder. To add a user control to your project add a module shown below.

    ControlTemplates

    4.4 Resources: This folder will contain a list of resources files if your application supports multiple languages. This is a SharePoint 15 hive mapped folder.

    4.5 Webparts: This folder will contain a list of webparts if your application supports any. Depending upon your need use a template of web part or Visual web part.

    web part

    Note: Kindly update the .webpart file with appropriate values for Title, Description, Group etc.
Read more articles on SharePoint: