display UsageData of sharepoint site.

Sagarp
Posted by Sagarp under Others category on | Points: 40 | Views : 4581
<%@ Page Language="C#" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="Microsoft.SharePoint.Administration" %>
<%@ Import Namespace="System.Collections.Generic" %>

<script type="text/c#" runat="server">

protected void Page_Load(object sender, EventArgs e)
{

DataGrid datagrid1 = new DataGrid();
DataGrid datagrid2 = new DataGrid();
DataGrid datagrid3 = new DataGrid();
DataGrid datagrid4 = new DataGrid();
DataGrid datagrid5 = new DataGrid();
DataGrid datagrid6 = new DataGrid();
DataGrid datagrid7 = new DataGrid();
DataGrid datagrid8 = new DataGrid();
DataGrid datagrid9 = new DataGrid();
DataGrid datagrid10 = new DataGrid();
Label Label1 = new Label();
Label Label2 = new Label();
Label Label3 = new Label();
Label Label4 = new Label();
Label Label5 = new Label();
Label Label6 = new Label();
Label Label7 = new Label();
Label Label8 = new Label();
Label Label9 = new Label();
Label Label10 = new Label();
Label1.Text = "Site Usage Data : User + Day";
Label1.ForeColor = System.Drawing.Color.Red;
Label2.Text = "Site Usage Data : User + Last Month";
Label2.ForeColor = System.Drawing.Color.Red;
Label3.Text = "Site Usage Data : url + Day";
Label3.ForeColor = System.Drawing.Color.Red;
Label4.Text = "Site Usage Data : url + Last Month";
Label4.ForeColor = System.Drawing.Color.Red;
Label5.Text = "Site Usage Data : refUrl + Day";
Label5.ForeColor = System.Drawing.Color.Red;
Label6.Text = "Site Usage Data : refUrl + Last Month";
Label6.ForeColor = System.Drawing.Color.Red;
Label7.Text = "Site Usage Data : os + Day";
Label7.ForeColor = System.Drawing.Color.Red;
Label8.Text = "Site Usage Data : os + Last Month";
Label8.ForeColor = System.Drawing.Color.Red;
Label9.Text = "Site Usage Data : browser + Day";
Label9.ForeColor = System.Drawing.Color.Red;
Label10.Text = "Site Usage Data : browser + Last Month";
Label10.ForeColor = System.Drawing.Color.Red;

SPWeb oWeb = new SPSite("http://sername/sites/test").RootWeb;
//SPWeb oWeb = SPContext.Current.Web;
DataTable datatable1 = oWeb.GetUsageData(Microsoft.SharePoint.Administration.SPUsageReportType.user, Microsoft.SharePoint.Administration.SPUsagePeriodType.day);
datagrid1.DataSource = datatable1;
datagrid1.DataBind();
DataTable datatable2 = oWeb.GetUsageData(Microsoft.SharePoint.Administration.SPUsageReportType.user, Microsoft.SharePoint.Administration.SPUsagePeriodType.lastMonth);
datagrid2.DataSource = datatable2;
datagrid2.DataBind();
DataTable datatable3 = oWeb.GetUsageData(Microsoft.SharePoint.Administration.SPUsageReportType.url, Microsoft.SharePoint.Administration.SPUsagePeriodType.day);
datagrid3.DataSource = datatable3;
datagrid3.DataBind();
DataTable datatable4 = oWeb.GetUsageData(Microsoft.SharePoint.Administration.SPUsageReportType.url, Microsoft.SharePoint.Administration.SPUsagePeriodType.lastMonth);
datagrid4.DataSource = datatable4;
datagrid4.DataBind();
DataTable datatable5 = oWeb.GetUsageData(Microsoft.SharePoint.Administration.SPUsageReportType.refUrl, Microsoft.SharePoint.Administration.SPUsagePeriodType.day);
datagrid5.DataSource = datatable5;
datagrid5.DataBind();
DataTable datatable6 = oWeb.GetUsageData(Microsoft.SharePoint.Administration.SPUsageReportType.refUrl, Microsoft.SharePoint.Administration.SPUsagePeriodType.lastMonth);
datagrid6.DataSource = datatable6;
datagrid6.DataBind();
DataTable datatable7 = oWeb.GetUsageData(Microsoft.SharePoint.Administration.SPUsageReportType.os, Microsoft.SharePoint.Administration.SPUsagePeriodType.day);
datagrid7.DataSource = datatable7;
datagrid7.DataBind();
DataTable datatable8 = oWeb.GetUsageData(Microsoft.SharePoint.Administration.SPUsageReportType.os, Microsoft.SharePoint.Administration.SPUsagePeriodType.lastMonth);
datagrid8.DataSource = datatable8;
datagrid8.DataBind();
DataTable datatable9 = oWeb.GetUsageData(Microsoft.SharePoint.Administration.SPUsageReportType.browser, Microsoft.SharePoint.Administration.SPUsagePeriodType.day);
datagrid9.DataSource = datatable9;
datagrid9.DataBind();
DataTable datatable10 = oWeb.GetUsageData(Microsoft.SharePoint.Administration.SPUsageReportType.browser, Microsoft.SharePoint.Administration.SPUsagePeriodType.lastMonth);
datagrid10.DataSource = datatable10;
datagrid10.DataBind();

Controls.Add(Label1);
Controls.Add(datagrid1);
Controls.Add(Label2);
Controls.Add(datagrid2);
Controls.Add(Label3);
Controls.Add(datagrid3);
Controls.Add(Label4);
Controls.Add(datagrid4);
Controls.Add(Label5);
Controls.Add(datagrid5);
Controls.Add(Label6);
Controls.Add(datagrid6);
Controls.Add(Label7);
Controls.Add(datagrid7);
Controls.Add(Label8);
Controls.Add(datagrid8);
Controls.Add(Label9);
Controls.Add(datagrid9);
Controls.Add(Label10);
Controls.Add(datagrid10);

}
</script>

Comments or Responses

Posted by: Raja on: 2/11/2011 Level:Starter | Status: [Member] | Points: 10
Hi Sagar,

Please explain the code as well, I could see there is a large block of code but lack of explanation is making it difficult to understand.

Thanks

Login to post response