I want to get the Usage Report of SharePoint subsite through C#.
What i am doing is that i am passing a sharepoint url in a textbox.After clicking the submit button it will populate the names of all subsites in a dropdown list of that particular given URL. These things are working fine.Later when i select a particular subsite name from the dropdownlist and click another button,am unable to get the user usage report of that subsite.
The method GetUsageData()
is giving me Object reference not set to an instance of an object.
string sitename;
sitename = DropDownList1.SelectedItem.Text;
SPSite mySiteCollection = new SPSite(TextBox1.Text);
SPWeb site = mySiteCollection.AllWebs[sitename];
System.Data.DataTable usageTable = new System.Data.DataTable();
usageTable = site.GetUsageData(SPUsageReportType.user, SPUsagePeriodType.day);
DGUsers.DataSource = usageTable;
DGUsers.DataBind();
PlaceHolder1.Controls.Add(DGUsers);