Friday, March 18, 2016

SharePoint 2010 Size and Performance Recommendations

This post will answer all the below questions :

How many web applications can we have in SharePoint 2010?
How big should be the Content database?
How many site Collections can I create?
How many sub sites can I create? etc...

Web application limits -

The following table lists the recommended guidelines for Web applications.

Content database - 300 per Web application Supported.
With 300 content databases per Web application, end user operations such as navigating to the site or site collections are not affected. But administrative operations such as creating a new site collection will experience performance degradation. We recommend that you use Windows® PowerShell™ to manage the Web application when a large number of content databases are present.

Zones - 5 per Web application.
The number of zones defined for a farm is hard coded to 5. Zones include Default, Intranet, Extranet, Internet, and custom.

Managed path - 20 per Web application Supported
Managed paths are cached on the Web server, and CPU resources are used to process incoming requests against the managed path list. If you plan to exceed twenty managed paths in a given Web application, we recommend that you test for acceptable system performance.

Content database limits - 


Content database size - 200 GB per Content database Supported
We strongly recommended limiting the size of content databases to 200 GB to help ensure system performance. Content database sizes up to 1 terabyte are supported only for large, single-site repositories and archives with non-collaborative I/O and usage patterns, such as Records Centers.

Site collection limits
The following table lists the recommended guidelines for site collections.


Number of Site - 250,000 per site collection Supported

The maximum recommended number of sites and subsites is 250,000 sites.
You can create a very large total number of Web sites by nesting subsites. For example, in a shallow hierarchy with 100 sites, each with 1,000 subsites, you would have a total of 100,000 Web sites. Or a deep hierarchy with 100 sites, each with 10 subsite levels would also contain a total of 100,000 Web sites.

Site collection size - 100 GB per site collection Supported.
A site collection should not exceed 100 GB unless it is the only site collection in the database. Certain site collection actions, such as site collection backup/restore or Move-SPSite, cause large Microsoft SQL Server® operations which can have performance impact or fail if other site collections are active in the same database.


List and library limits - 


List Items - 30,000,000 per list Supported.
You can create very large lists using standard views, site hierarchies, and metadata navigation. This value may vary depending on the number of columns in the list and the usage of the list.

Documents - 30,000,000 per library Supported.
You can create very large document libraries by nesting folders, using standard views and site hierarchy.

Sites and Subsites - 

Subsite - 2,000 per site.
The interface for enumerating subsites of a given Web site does not perform well as the number of subsites surpasses 2,000. Similarly, the All Site Content page and the Tree View Control performance will degrade significantly as the number of subsites grows.

Web Parts -


Web parts - 25 per wiki Page or Web part page
This figure is an estimate based on simple Web Parts.

SharePoint 2010 - Creating an Event Receiver


In the previous post, we had an overview of Event Receivers. In this post we will actually create an event receiver to understand the basic functionality.

Objective
We need to accomplish the following tasks for this demo:
1) Create a custom list named 'Customers' with just name and address.
2) Create a custom list named 'Orders' and add Customer's 'Title' as a lookup field.
3) Add an event handler to retrieve the Customer's 'Address' and save it as 'Shipping address' in the Orders list in the ItemAdding event.

Steps for creating the event receiver
Following are the steps for creating the Event Receiver.

1) Create a custom list named "Customers" with the fields as shown in the following figure.


2) Enter some sample data in the "Customers" list.

3) Create another custom list named "Orders" with the fields as shown in the following figure. Make sure "Title" field from "Customers" List is added as lookup field in this list.


4) Create sample data for Orders list and leave the "ShippingAddress" filed blank.

5) Right now "ShippingAddress" field remains blank.

We need to target that whenever a new item is created, the "ShippingAddress" field should be updated with the value from "Address" field in the "Customers" List.

6) Open Visual Studio 2010 and create a new project named "EventReceiverDemo". Add a new feature named "OrderProcess" scoped as web.

7) Right click on the solution and add a new EventReceiver named "OrdersEventReceiver" as follows.

8) You will be prompted with a dialogue for choosing the List Type (eg: Custom list, Announcement etc) and the event that will bind with this list. Choose "An item is being added".

9) A new class is created named OrdersEventReceiver inherited from SPItemEventReceiver base class which contains the ItemAddingEvent.

10) Added the following code in the ItemAdding Event. Its just a simple code for getting the Customer Name (ID;#Title format) from the current item being saved. Using the 'Id' we get the details from the "Customers" List and update in the "ShippingAddress" filed of the current.

public class OrdersEventReceiver : SPItemEventReceiver
    {
       public override void ItemAdding(SPItemEventProperties properties)
       {
           base.ItemAdding(properties);
           //Elevate the permissions to Admin level for performing this operation.
           SPSecurity.RunWithElevatedPrivileges(delegate {
               
               //Get the selected Customer's Look up Title which is in the form of "1;#NealMukundan".             
               SPListItem CurrentItem = properties.ListItem;
               String strCustomer = CurrentItem["Customer"].ToString();
               
               //Get the selected Customer's ID using Substring
               int startPos = 0;
               int endPos = CurrentItem["Customer"].ToString().IndexOf(";#");
               int Cust_ID = Convert.ToInt32(strCustomer.Substring(startPos, endPos));
 
               //Get the list items from 'Customers' List using Customer ID.
               SPWeb oWeb = properties.Web;
               SPList oList = oWeb.Lists["Customers"];
               SPListItem Customers = oList.GetItemById(Cust_ID);
 
               //Assign the 'Address' from Customers List to the 'Shipping Address' in the Current Item.
               CurrentItem["ShippingAddress"] = Customers["Address"];
 
               //Update the current item
               oWeb.AllowUnsafeUpdates = true;
               oWeb.Update(); 
               oWeb.AllowUnsafeUpdates = false;           
           });
       }
    }
11) Now that we have created the Event Receiver, we must bind it to the 'Orders' List using a Feature Receiver.

12) Right click on the Feature and an new Feature Receiver as follows.

13) Open the 'Elements.xml' linked to the 'OrdersEventReceiver.cs' file since we will use this data to override the Feature Receiver Events.

14) Added the following code in the FeatureActivated event. We need to create an event receiver definition using theSPEventReceiverDefinition class. You can get the values for definition from the XML file mentioned in the previous step.
public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPSecurity.RunWithElevatedPrivileges(delegate {
                //Get the List instance from the Fetaure Properties
                SPWeb oWeb = (SPWeb)properties.Feature.Parent;
                SPList oList = oWeb.Lists["Orders"];
                //Add event receiver definition to the 'Orders' List
                SPEventReceiverDefinition oDefinition = oList.EventReceivers.Add();
                oDefinition.Assembly = Assembly.GetExecutingAssembly().FullName;
                oDefinition.Class = "EventReceiverDemo.OrdersEventReceiver";
                oDefinition.Type = SPEventReceiverType.ItemAdded;
                oDefinition.SequenceNumber = 10005;
                oDefinition.Name = "OrdersEventReceiverItemAdding";
                oDefinition.Data = null;
                oDefinition.Update();
            });            
        }
15) Added the following code in the FeatureDeactivating event. We need to remove the event receiver definition from SPEventReceiverDefinitionCollection.
public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            SPSecurity.RunWithElevatedPrivileges(delegate {
                //Get the List instance from the Fetaure Properties
                SPWeb oWeb = (SPWeb)properties.Feature.Parent;
                SPList oList = oWeb.Lists["Orders"];
                //Remove event receiver definition from 'Orders' List
                SPEventReceiverDefinitionCollection oColl = oList.EventReceivers;
                foreach (SPEventReceiverDefinition oDefinition in oColl)
                {
                    if (oDefinition.Name == "OrdersEventReceiverItemAdding")
                    {
                        oColl[oDefinition.Id].Delete();
                        break;
                    }
                }
            });                        
        }
16) Now deploy the solution and activate the "OrderProcess" Feature.

17) Go to the "Orders" list and create a new item.

18) As shown in the following figure, the "ShippingAddress" field will be automatically updated.

19) If the "OrderProcess" Feature is deactivated then the event receiver will be removed and the "ShippingAddress" field will no longer be updated.

Creating Provider hosted app (sharepoint online) with local hosted IIS

The Pre-requires are as follows. 1. Office 365 Subscription 2. Visual Studio 2015 (Professional/Community/Enterprise Edition) With t...