SPWeb.GetUsageData Method (SPUsageReportType, SPUsagePeriodType, Int32, DateTime) (Microsoft.SharePoint)
Returns a table that contains information about the usage of a Web site 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)
Syntax

Visual Basic (Declaration)
Public Function GetUsageData ( _
    itemType As SPUsageReportType, _
    periodType As SPUsagePeriodType, _
    numColsToDisplay As Integer, _
    lastDayToDisplay As DateTime _
) As DataTable
Visual Basic (Usage)
Dim instance As SPWeb
Dim itemType As SPUsageReportType
Dim periodType As SPUsagePeriodType
Dim numColsToDisplay As Integer
Dim lastDayToDisplay As DateTime
Dim returnValue As DataTable

returnValue = instance.GetUsageData(itemType, periodType, numColsToDisplay, lastDayToDisplay)
C#
public DataTable GetUsageData (
    SPUsageReportType itemType,
    SPUsagePeriodType periodType,
    int numColsToDisplay,
    DateTime lastDayToDisplay
)

Parameters

itemType

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

periodType

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

numColsToDisplay

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

lastDayToDisplay

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

A System.Data.DataTable object that contains the information.
Remarks

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 method of Remote Procedure Call (RPC) protocol returns all usage data.

Example

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.

Visual Basic
Using webSite As SPWeb = SPContext.Current.Site.OpenWeb("Site_Name")
    Dim dateValue As System.DateTime = System.DateTime.Today
    dateValue = dateValue.AddDays(- 1)

    DataGrid1.DataSource = webSite.GetUsageData(SPUsageReportType.user, SPUsagePeriodType.day, 12, dateValue)

    DataGrid1.DataBind()
End Using
C#
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 Best Practices: Using Disposable Windows SharePoint Services Objects.

See Also

Tags :


Page view tracker