SPWeb.GetUsageData method (SPUsageReportType, SPUsagePeriodType)

Gets a table that contains information about the usage of a website, based on the specified report type and time interval.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)


Public Function GetUsageData ( _
    itemType As SPUsageReportType, _
    periodType As SPUsagePeriodType _
) As DataTable
Dim instance As SPWeb
Dim itemType As SPUsageReportType
Dim periodType As SPUsagePeriodType
Dim returnValue As DataTable

returnValue = instance.GetUsageData(itemType, _
public DataTable GetUsageData(
    SPUsageReportType itemType,
    SPUsagePeriodType periodType


Return value

Type: System.Data.DataTable
A System.Data.DataTable object that contains the information.


The GetUsageData method returns only 2000 records from the usage data for the site, while the GetUsageBlob method of Remote Procedure Call (RPC) protocol returns all usage data.


The following code example populates a DataGrid control with information about the number of hits by type of browser that a website received during the last month.

This example requires using directives (Imports in Microsoft Visual Basic) for the Microsoft.SharePoint and Microsoft.SharePoint.Administration namespaces.

The example assumes the presence of a DataGrid control.

Using webSite As SPWeb = SPContext.Current.Site.OpenWeb("Site_Name")
    DataGrid1.DataSource = webSite.GetUsageData(SPUsageReportType.browser, SPUsagePeriodType.lastMonth)

End Using
using (SPWeb oWebsite = SPContext.Current.Site.OpenWeb("Website_URL"))
    DataGrid1.DataSource = 
    oWebsite.GetUsageData(SPUsageReportType.browser, SPUsagePeriodType.lastMonth);


Certain objects implement the IDisposable interface, and you must avoid retaining these objects in memory after they are no longer needed. For information about good coding practices, see Disposing Objects.

See also


SPWeb class

SPWeb members

GetUsageData overload

Microsoft.SharePoint namespace