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)
Available in Sandboxed Solutions: No

Syntax

'Declaration
<SubsetCallableExcludeMemberAttribute(SubsetCallableExcludeMemberType.UnsupportedSPType)> _
Public Function GetUsageData ( _
    itemType As SPUsageReportType, _
    periodType As SPUsagePeriodType _
) As DataTable
'Usage
Dim instance As SPWeb
Dim itemType As SPUsageReportType
Dim periodType As SPUsagePeriodType
Dim returnValue As DataTable

returnValue = instance.GetUsageData(itemType, _
    periodType)
[SubsetCallableExcludeMemberAttribute(SubsetCallableExcludeMemberType.UnsupportedSPType)]
public DataTable GetUsageData(
    SPUsageReportType itemType,
    SPUsagePeriodType periodType
)

Parameters

Return Value

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

Remarks

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

Examples

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)

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

Note

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

Reference

SPWeb Class

SPWeb Members

GetUsageData Overload

Microsoft.SharePoint Namespace