Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

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)
[SubsetCallableExcludeMemberAttribute(SubsetCallableExcludeMemberType.UnsupportedSPType)]
public DataTable GetUsageData(
	SPUsageReportType itemType,
	SPUsagePeriodType periodType
)

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.

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 (SPWeb oWebsite = SPContext.Current.Site.OpenWeb("Website_URL"))
{
    DataGrid1.DataSource = 
    oWebsite.GetUsageData(SPUsageReportType.browser, SPUsagePeriodType.lastMonth);
    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.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.