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)
Available in Sandboxed Solutions: No
Syntax
'Declaration
<SubsetCallableExcludeMemberAttribute(SubsetCallableExcludeMemberType.UnsupportedSPType)> _
Public Function GetUsageData ( _
itemType As SPUsageReportType, _
periodType As SPUsagePeriodType, _
numColsToDisplay As Integer, _
lastDayToDisplay As DateTime _
) As DataTable
'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)
[SubsetCallableExcludeMemberAttribute(SubsetCallableExcludeMemberType.UnsupportedSPType)]
public DataTable GetUsageData(
SPUsageReportType itemType,
SPUsagePeriodType periodType,
int numColsToDisplay,
DateTime lastDayToDisplay
)
Parameters
itemType
Type: Microsoft.SharePoint.Administration.SPUsageReportTypeAn SPUsageReportType value that specifies the type of report to be created.
periodType
Type: Microsoft.SharePoint.Administration.SPUsagePeriodTypeAn SPUsagePeriodType value that specifies the time interval to use in the information that is returned.
numColsToDisplay
Type: System.Int32A 32-bit integer that specifies the number of columns to return in the table.
lastDayToDisplay
Type: System.DateTimeA 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.
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.
Examples
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 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
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();
}
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.