SPWeb.GetUsageData method (SPUsageReportType, SPUsagePeriodType, Int32, DateTime)

Gets a table that contains information about the usage of a website based on the specified report type, time interval, number of columns to display, and last day to display.

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

public DataTable GetUsageData(
	SPUsageReportType itemType,
	SPUsagePeriodType periodType,
	int numColsToDisplay,
	DateTime lastDayToDisplay
)

Parameters

itemType
Type: Microsoft.SharePoint.Administration.SPUsageReportType

An SPUsageReportType value that specifies the type of report to be created.

periodType
Type: Microsoft.SharePoint.Administration.SPUsagePeriodType

An SPUsagePeriodType value that specifies the time interval to use in the information that is returned.

numColsToDisplay
Type: System.Int32

A 32-bit integer that specifies the number of columns to return in the table.

lastDayToDisplay
Type: System.DateTime

A System.DateTime value that specifies the most recent day to represent in the information that is returned. The value that is passed in this parameter must specify a time that is greater than or equal to the last time usage processing was run for the site.

Return value

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

The GetUsageData method returns undefined results when invalid parameters are passed (for example, a date from 100 years ago). If the value passed in the numColsToDisplay parameter is out of range, 31 columns are returned.

This 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 12 columns of information about the usage of a site, starting from yesterday.

This example also assumes the presence of a DataGrid control.

using (SPWeb oWebsite = SPContext.Current.Site.OpenWeb("Website_URL"))
{
    System.DateTime dtValue = System.DateTime.Today;
    dtValue = dtValue.AddDays(-1);
    DataGrid1.DataSource = 
        oWebsite.GetUsageData(SPUsageReportType.user, SPUsagePeriodType.day, 
        12, dtValue);
    DataGrid1.DataBind();
}
NoteNote

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.

Show: