Display Monthly Usage Analysis Report of SharePoint Site

  1. <%@ Page Language="C#" %>  
  2.   
  3. <%@ Import Namespace="Microsoft.SharePoint" %>  
  4.   
  5. <%@ Import Namespace="System.Data" %>  
  6.   
  7. <%@ Import Namespace="System.Net" %>  
  8.   
  9. <%@ Import Namespace="Microsoft.SharePoint.Administration" %>  
  10.   
  11. <%@ Import Namespace="System.Collections.Generic" %>     
  12.   
  13. <script type="text/c#" runat="server">    
  14.   
  15. protected void Page_Load(object sender, EventArgs e)  
  16.   
  17. {    
  18.         DataGrid datagrid1 = new DataGrid();  
  19.   
  20.         DataGrid datagrid2 = new DataGrid();  
  21.   
  22.         DataGrid datagrid3 = new DataGrid();  
  23.   
  24.         DataGrid datagrid4 = new DataGrid();  
  25.   
  26.         DataGrid datagrid5 = new DataGrid();  
  27.   
  28.         DataGrid datagrid6 = new DataGrid();  
  29.   
  30.         DataGrid datagrid7 = new DataGrid();  
  31.   
  32.         DataGrid datagrid8 = new DataGrid();  
  33.   
  34.         DataGrid datagrid9 = new DataGrid();  
  35.   
  36.         DataGrid datagrid10 = new DataGrid();  
  37.   
  38.         Label Label1 = new Label();  
  39.   
  40.         Label Label2 = new Label();  
  41.   
  42.         Label Label3 = new Label();  
  43.   
  44.         Label Label4 = new Label();  
  45.   
  46.         Label Label5 = new Label();  
  47.   
  48.         Label Label6 = new Label();  
  49.   
  50.         Label Label7 = new Label();  
  51.   
  52.         Label Label8 = new Label();  
  53.   
  54.         Label Label9 = new Label();       
  55.   
  56.         Label Label10 = new Label();  
  57.   
  58.         Label1.Text = "Site Usage Data : User + Day";  
  59.   
  60.         Label1.ForeColor = System.Drawing.Color.Red;  
  61.   
  62.         Label2.Text = "Site Usage Data : User + Last Month";  
  63.   
  64.         Label2.ForeColor = System.Drawing.Color.Red;  
  65.   
  66.         Label3.Text = "Site Usage Data : url + Day";  
  67.   
  68.         Label3.ForeColor = System.Drawing.Color.Red;  
  69.   
  70.         Label4.Text = "Site Usage Data : url + Last Month";  
  71.   
  72.         Label4.ForeColor = System.Drawing.Color.Red;  
  73.   
  74.         Label5.Text = "Site Usage Data : refUrl + Day";  
  75.   
  76.         Label5.ForeColor = System.Drawing.Color.Red;  
  77.   
  78.         Label6.Text = "Site Usage Data : refUrl + Last Month";  
  79.   
  80.         Label6.ForeColor = System.Drawing.Color.Red;  
  81.   
  82.         Label7.Text = "Site Usage Data : os + Day";  
  83.   
  84.         Label7.ForeColor = System.Drawing.Color.Red;  
  85.   
  86.         Label8.Text = "Site Usage Data : os + Last Month";  
  87.   
  88.         Label8.ForeColor = System.Drawing.Color.Red;  
  89.   
  90.         Label9.Text = "Site Usage Data : browser + Day";  
  91.   
  92.         Label9.ForeColor = System.Drawing.Color.Red;  
  93.   
  94.         Label10.Text = "Site Usage Data : browser + Last Month";  
  95.   
  96.         Label10.ForeColor = System.Drawing.Color.Red;    
  97.   
  98.   
  99.                 SPWeb oWeb = new SPSite("http://sername/sites/test").RootWeb;  
  100.   
  101.                 //SPWeb oWeb = SPContext.Current.Web;   
  102.   
  103.                 DataTable datatable1 = oWeb.GetUsageData(Microsoft.SharePoint.Administration.SPUsageReportType.user, Microsoft.SharePoint.Administration.SPUsagePeriodType.day);   
  104.   
  105.                 datagrid1.DataSource = datatable1;  
  106.   
  107.                 datagrid1.DataBind();  
  108.   
  109.                 DataTable datatable2 = oWeb.GetUsageData(Microsoft.SharePoint.Administration.SPUsageReportType.user, Microsoft.SharePoint.Administration.SPUsagePeriodType.lastMonth);            
  110.   
  111.                 datagrid2.DataSource = datatable2;  
  112.   
  113.                 datagrid2.DataBind();  
  114.   
  115.                 DataTable datatable3 = oWeb.GetUsageData(Microsoft.SharePoint.Administration.SPUsageReportType.url, Microsoft.SharePoint.Administration.SPUsagePeriodType.day);                   
  116.   
  117.                 datagrid3.DataSource = datatable3;  
  118.   
  119.                 datagrid3.DataBind();  
  120.   
  121.                 DataTable datatable4 = oWeb.GetUsageData(Microsoft.SharePoint.Administration.SPUsageReportType.url, Microsoft.SharePoint.Administration.SPUsagePeriodType.lastMonth);             
  122.   
  123.                 datagrid4.DataSource = datatable4;  
  124.   
  125.                 datagrid4.DataBind();  
  126.   
  127.                 DataTable datatable5 = oWeb.GetUsageData(Microsoft.SharePoint.Administration.SPUsageReportType.refUrl, Microsoft.SharePoint.Administration.SPUsagePeriodType.day);                
  128.   
  129.                 datagrid5.DataSource = datatable5;  
  130.   
  131.                 datagrid5.DataBind();  
  132.   
  133.                 DataTable datatable6 = oWeb.GetUsageData(Microsoft.SharePoint.Administration.SPUsageReportType.refUrl, Microsoft.SharePoint.Administration.SPUsagePeriodType.lastMonth);                  
  134.   
  135.                 datagrid6.DataSource = datatable6;  
  136.   
  137.                 datagrid6.DataBind();  
  138.   
  139.                 DataTable datatable7 = oWeb.GetUsageData(Microsoft.SharePoint.Administration.SPUsageReportType.os, Microsoft.SharePoint.Administration.SPUsagePeriodType.day);            
  140.   
  141.                 datagrid7.DataSource = datatable7;  
  142.   
  143.                 datagrid7.DataBind();  
  144.   
  145.                 DataTable datatable8 = oWeb.GetUsageData(Microsoft.SharePoint.Administration.SPUsageReportType.os, Microsoft.SharePoint.Administration.SPUsagePeriodType.lastMonth);              
  146.   
  147.                 datagrid8.DataSource = datatable8;  
  148.   
  149.                 datagrid8.DataBind();  
  150.   
  151.                 DataTable datatable9 = oWeb.GetUsageData(Microsoft.SharePoint.Administration.SPUsageReportType.browser, Microsoft.SharePoint.Administration.SPUsagePeriodType.day);               
  152.   
  153.                 datagrid9.DataSource = datatable9;  
  154.   
  155.                 datagrid9.DataBind();  
  156.   
  157.                 DataTable datatable10 = oWeb.GetUsageData(Microsoft.SharePoint.Administration.SPUsageReportType.browser, Microsoft.SharePoint.Administration.SPUsagePeriodType.lastMonth);                
  158.   
  159.                 datagrid10.DataSource = datatable10;  
  160.   
  161.                 datagrid10.DataBind();  
  162.   
  163.                   
  164.   
  165.                 Controls.Add(Label1);  
  166.   
  167.                 Controls.Add(datagrid1);  
  168.   
  169.                 Controls.Add(Label2);  
  170.   
  171.                 Controls.Add(datagrid2);  
  172.   
  173.                 Controls.Add(Label3);  
  174.   
  175.                 Controls.Add(datagrid3);  
  176.   
  177.                 Controls.Add(Label4);  
  178.   
  179.                 Controls.Add(datagrid4);  
  180.   
  181.                 Controls.Add(Label5);  
  182.   
  183.                 Controls.Add(datagrid5);  
  184.   
  185.                 Controls.Add(Label6);  
  186.   
  187.                 Controls.Add(datagrid6);  
  188.   
  189.                 Controls.Add(Label7);  
  190.   
  191.                 Controls.Add(datagrid7);  
  192.   
  193.                 Controls.Add(Label8);  
  194.   
  195.                 Controls.Add(datagrid8);  
  196.   
  197.                 Controls.Add(Label9);  
  198.   
  199.                 Controls.Add(datagrid9);  
  200.   
  201.                 Controls.Add(Label10);  
  202.   
  203.                 Controls.Add(datagrid10);    
  204.   
  205.   
  206. }  
  207.   
  208. </script>