Quota Templates in SharePoint 2010


In this article we will be seeing about the quota templates in SharePoint 2010.

Introduction:

A quota template consists of storage limit values that specify the maximum amount of data that can be stored in a site collection. When the storage limit is reached, a quota template can also trigger an e-mail alert to the site collection administrator. You can create a quota template that can be applied to any site collection in the farm. The storage limit applies to the sum of the content sizes for the top-level site and all subsites within the site collection.

The quota templates can also be applied to a site collection that contains sandbox solutions. The maximum usage per day can be limited and cause a warning e-mail message to be sent when the usage limit is approaching. 

The existing quota templates can be modified which allows modifying the storage limits for all the site collections that use the same quota template. The quota templates can also be deleted if necessary.

Configure Quota templates:

Go to Central administration => Application Management => Site Collections =>Specify Quota templates.

QuotaTemplate.jpg

You can modify the existing quota template or you can create a new quota template.

QuotaTemplate1.jpg 

Get all available quota templates using object model:
  • Open Visual Studio 2010. 
  • Go to File => New => Project. 
  • Select Console Application template from the installed templates. 
  • Enter the Name and click Ok. 
  • Add the following assembly.

    Microsoft.SharePoint.dll
  • Add the following namespace.

    Using Microsoft.SharePoint ;
    Using Microsoft.SharePoint.Administration ;
  • Program.cs looks like the following.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.Administration;
    namespace QuotaTemplates
    {
        class Program
        {
            static void Main(string[] args)
            {
                //Get all the quota templates  
                SPWebService contentService = SPWebService.ContentService;
                foreach (SPQuotaTemplate quotaTemplate in contentService.QuotaTemplates)
                {
                    long StorageMaximumLevel = (quotaTemplate.StorageMaximumLevel) / (1024 * 1024);
                    long StorageWarningLevel = (quotaTemplate.StorageWarningLevel) / (1024 * 1024);
                    double UserCodeMaximumLevel = (quotaTemplate.UserCodeMaximumLevel);
                    double UserCodeWarningLevel = (quotaTemplate.UserCodeWarningLevel);
                    Console.WriteLine("Name: {0},QuotaID: {1},StorageMaximumLevel: {2}MB,StorageWarningLevel: {3}MB,UserCodeMaximumLevel: {4}MB, UserCodeWarningLevel: {5}MB ", quotaTemplate.Name, quotaTemplate.QuotaID, StorageMaximumLevel, StorageWarningLevel, UserCodeMaximumLevel, UserCodeWarningLevel);
                }
                Console.ReadLine();
            }
        }
    }
  • Build the solution.
  • Hit F5.
Note:

SPWebService - Used to represent a Web service that contains one or more Web applications. This Web service allows a Web browser to access the content in SharePoint sites.

SPWebService.ContentService - Gets the Web service associated with the content application.

SPQuotaTemplate - Used to represent a reusable definition of a quota that is applied to SharePoint sites in the deployment. 

Get all available quota templates using powershell:
  • Go to Start => All Programs => Microsoft SharePoint 2010 products => SharePoint 2010 Management Shell. 
  • Run as an administrator. 
  • Run the following script.

    $contentService =[Microsoft.SharePoint.Administration.SPWebService]::ContentService
    foreach ($quotaTemplate in $contentService.QuotaTemplates)
    {
        [long]$StorageMaximumLevel = $quotaTemplate.StorageMaximumLevel 
        [long]$StorageWarningLevel = $quotaTemplate.StorageWarningLevel
        [double]$UserCodeMaximumLevel = $quotaTemplate.UserCodeMaximumLevel
        [double]$UserCodeWarningLevel = $quotaTemplate.UserCodeWarningLevel
        write-host Name: $quotaTemplate.Name ,QuotaID: $quotaTemplate.QuotaID,StorageMaximumLevel: $StorageMaximumLevel,StorageWarningLevel: $StorageWarningLevel ,UserCodeMaximumLevel: $UserCodeMaximumLevel UserCodeWarningLevel: $UserCodeWarningLevel
    }
Create new Quota template through UI:

Template Name:
  • Select "Create a new quota template".
  • Template to start from - select [new blank template] option from the drop down menu.
  • New template name - Enter the name of the new quota template.
Storage Limit Values:
  • Select "Limit site storage to a maximum of" and enter the value.
  • Select "Send warning E-mail when site collection storage reaches" and enter the value.
Storage Limit Values:
  • Enter the value for "Limit maximum usage per day to".
  • Select "Send warning e-mail when usage per day reaches" and enter the value.
  • Click on Ok.
Create new Quota template using object model:

            //Create a new quota template
            SPQuotaTemplate newQuotaTemplate = new SPQuotaTemplate();
            newQuotaTemplate.Name = "New Quota Template";
            newQuotaTemplate.StorageMaximumLevel = (150 * 1024) * 1024;
            newQuotaTemplate.StorageWarningLevel = (100 * 1024) * 1024;
            newQuotaTemplate.UserCodeMaximumLevel = 300;
            newQuotaTemplate.UserCodeWarningLevel = 300;
            SPWebService contentService = SPWebService.ContentService;
            contentService.QuotaTemplates.Add(newQuotaTemplate);
            contentService.Update();

  • Build the solution.
  • Hit F5.
Create new Quota template using powershell:

$newQuotaTemplate = New-Object Microsoft.SharePoint.Administration.SPQuotaTemplate
$newQuotaTemplate.Name = "New Quota Template"
$newQuotaTemplate.StorageMaximumLevel = (150 * 1024) * 1024
$newQuotaTemplate.StorageWarningLevel = (100 * 1024) * 1024
$newQuotaTemplate.UserCodeMaximumLevel = 300
$newQuotaTemplate.UserCodeWarningLevel = 300
$contentService =[Microsoft.SharePoint.Administration.SPWebService]::ContentService
$contentService.QuotaTemplates.Add($newQuotaTemplate)
$contentService.Update()

Edit a Quota template through UI:

Template Name:
  • Select "Edit an existing template" and choose the template to be edited.
Storage Limit Values:
  • Select "Limit site storage to a maximum of" and enter the value.
  • Select "Send warning E-mail when site collection storage reaches" and enter the value.
Storage Limit Values:
  • Enter the value for "Limit maximum usage per day to".
  • Select "Send warning e-mail when usage per day reaches" and enter the value.
  • Click on Ok.
Edit a Quota template using object model:

            // Edit a quota template
            SPWebService contentService = SPWebService.ContentService;
            SPQuotaTemplate quotaTemplate = contentService.QuotaTemplates["My quota template"];
            quotaTemplate.Name = "Updated quota template";
            quotaTemplate.UserCodeMaximumLevel = 500;
            quotaTemplate.UserCodeWarningLevel = 500;
            contentService.Update();
        
Edit a Quota template using powershell:

$contentService =[Microsoft.SharePoint.Administration.SPWebService]::ContentService
$quotaTemplate = $contentService.QuotaTemplates["New Quota Template"];
$quotaTemplate.Name = "Updated quota template"
$quotaTemplate.UserCodeMaximumLevel = 500
$quotaTemplate.UserCodeWarningLevel = 500
$contentService.Update()

Delete a Quota template through UI:

Template Name:
  • Select "Edit an existing template" and choose the template you want to delete.
  • Click on Delete.
  • Quota template will be successfully deleted.
Delete a Quota template using object model:

            // Delete a quota template
            SPWebService contentService = SPWebService.ContentService;
            contentService.QuotaTemplates.Delete("Updated quota template");        

Delete a Quota template using powershell:

$contentService =[Microsoft.SharePoint.Administration.SPWebService]::ContentService
$contentService.QuotaTemplates.Delete("Updated quota template")

Assign the quota template to the site collection through UI:

Go to Central Administration => Application Management => Site Collections =>Configure quotas and locks.

QuotaTemplate2.jpg 

QuotaTemplate3.jpg

QuotaTemplate4.jpg

You can assign the quota template to a site collection by selecting the quota template in the Current quota template drop down menu [Site Quota Information].

Assign the quota template to the site collection using object model:

            //Assign the quota template to the site collection
            SPWebService contentService = SPWebService.ContentService;
            SPQuotaTemplate quotaTemplate = contentService.QuotaTemplates["My Custom Quota template"];
            using (SPSite site = new SPSite("http://servername:1273"))
            {
                site.Quota = quotaTemplate;
            }

Assign the quota template to the site collection using powershell:

$contentService =[Microsoft.SharePoint.Administration.SPWebService]::ContentService
$quotaTemplate = $contentService.QuotaTemplates["New Quota Template"]
$site = Get-SPSite "http://serverName:1273"
$site.quota=$quotaTemplate 

(or) 

$Url="http://serverName:1273"

Set-SPSite -Identity $Url -QuotaTemplate $quotaTemplate