lblMensage.Text = string.Empty;
dgvAudit.DataSource = null;
dgvAudit.Refresh();
SPSite mySite = new SPSite(txtMySiteURL.Text);
SPWeb myWeb = mySite.OpenWeb();
SPList myList = myWeb.Lists[txtLibraryName.Text];
if (ddlDocs.SelectedIndex >= 0)
{
SPListItem myDoc = myList.Items.GetItemById
(Convert.ToInt32(ddlDocs.SelectedIndex + 1));
SPAuditQuery myAuditQuery = new SPAuditQuery(mySite);
miAuditQuery.RestrictToListItem(myDoc);
SPAuditEntryCollection myAuditColeccion =
myList.Audit.GetEntries(myAuditQuery);
DataTable myTable = CrearDataTable();
if (myAuditColeccion.Count > 0)
{
foreach (SPAuditEntry myEntry in myAuditColeccion)
{
DataRow myLinea = myTabla.NewRow();
myRow["Date"] = myEntry.Occurred.ToString();
SPUser myUser = myWeb.SiteUsers.GetByID(myEntry.UserId);
myLinea["User"] = myUser.Name;
myLinea["Type Action"] = myEntry.Event.ToString();
myTable.Rows.Add(myLinea);
}
dgvAudit.DataSource = myTable;
dgvAudit.AutoResizeColumns();
}
else
lblMessage.Text = "No audit information for this document";
}
DataGrid 'dgvAudit' and DataTable 'myTable' show the data onscreen. After creating the objects in the normal
way, the code uses a query to find the specific data of the document. All the Audit entries of the Portal are saved
in one table of the Content DataBase, and the 'GetEntries' method returns the entire Table content. By using the
queries of the type 'SPAuditQuery' and the method 'RestricToListItem', it is possible to filter the data of the select-
ed document.
The pertinent data can be read by using a loop to create each row in the DataTable. Finally, the DataTable is con-
nected to the DataGrid, and parameters are configured to display it onscreen. A Label is used to indicate whether
any events are available for the document.
Conclusion
Careful registration of information in a Portal can be vitally important to a company, not only internally but also for
possible juridical consequences. SharePoint 2007 has the necessary infrastructure to gather and conserve the
12
Putting SharePoint to Work for You, an Internet.com Developer eBook. Copyright 2008, Jupitermedia Corp.
Putting SharePoint to Work for You
[
]