GetUsageData() in a web part returns null

2.1k Views Asked by At

I am trying to display some SharePoint usage data in a web part.

Here's my code:

SPSite spSiteCollection = new SPSite(myURL)
spSiteCollection.CatchAccessDeniedException = false;
SPWeb spWeb = spSiteCollection.OpenWeb();

DataTable dtResults = new DataTable();
dtResults = spWeb.GetUsageData(SPUsageReportType.url, SPUsagePeriodType.lastMonth);

The DataTable that is supposed to contain the results is always null. I also tried to run this from an aspx page but nothing.

1

There are 1 best solutions below

1
On

I think before you can retrieve any usage data you have to configure your farm and activate usage reporting.