Monday, June 22, 2009

Enable Audit settings for a Sharepoint List Programmatically

Share/Save/Bookmark

Sharepoint provides audit property for the objects that can be audited. Its pretty easy to turn on audit feature programmatically on any list/document library or a sitecolleciton by setting the values for the property. In the object model, for a SPList, SPListItem the audit property can be set on specific events so that it doesn’t generate huge data. Code as follows :

SPSite siteCollection = SPContext.Current.Site;
SPWeb site = siteCollection.RootWeb;
SPList docLib = site.Lists("DocLibName");
// Turn on auditing flags.
docLib.Audit.AuditFlags = SPAuditMaskType.View |
                          SPAuditMaskType.ChildDelete;
docLib.Audit.Update();

In the above example only view and delete events get audited, any more events to be audited can be added to audit flag separating Bitwise OR.

Auditing options:

SPAuditMaskType.CheckIn
SPAuditMaskType.CheckOut
SPAuditMaskType.ChildDelete
SPAuditMaskType.Copy
SPAuditMaskType.Delete
SPAuditMaskType.Move
SPAuditMaskType.ProfileChange
SPAuditMaskType.SchemaChange
SPAuditMaskType.Search
SPAuditMaskType.SecurityChange
SPAuditMaskType.Undelete
SPAuditMaskType.Update
SPAuditMaskType.View
SPAuditMaskType.Workflow

Subscribe

Read Sharepoint Audit log reports

Share/Save/Bookmark

The audit log data enabled for a site collection can be read programmatically as follows:

SPSite siteCollection = SPContext.Current.Site;
SPAuditQuery wssQuery = new SPAuditQuery(siteCollection);
SPAuditEntryCollection auditCol;
auditCol = siteCollection.Audit.GetEntries(wssQuery);
// enumerate through audit log and read entries
foreach (SPAuditEntry entry in auditCol) {
    // inspect entry
}

Reading the log data can be a performance issue if all the entries are looped, so restrict the entries to either a list,listitem or a user using methods RestrictToList or ResstrictToListItem, RestrictToUser. SetRangeStart and SetRangeEnd methods on SPAuditQuery class can be used to get the logs for a limited period.


Subscribe

Monday, June 8, 2009

Permission Levels and Permissions

Share/Save/Bookmark

By default sharepoint creates 5 permission levels, each has its own permissions associated.In case, to customize the permissions associated with a specifc level all 3 levels(except limited access and Full Control) can be modified.

Default permission levels in Windows SharePoint Services 3.0
Permission Level
Description
Full Control
This permission level contains all permissions. Assigned to the Site name Owners SharePoint group, by default. This permission level cannot be customized or deleted.
Design
Can create lists and document libraries, edit pages and apply themes, borders, and style sheets in the Web site. Not assigned to any SharePoint group, by default.
Contribute
Can add, edit, and delete items in existing lists and document libraries. Assigned to the Site name Members SharePoint group, by default.
Read
Read-only access to the Web site. Users and SharePoint groups with this permission level can view items and pages, open items, and documents. Assigned to the Site name Visitors SharePoint group, by default.
Limited Access
The Limited Access permission level is designed to be combined with fine-grained permissions to give users access to a specific list, document library, item, or document, without giving them access to the entire site. However, to access a list or library, for example, a user must have permission to open the parent Web site and read shared data such as the theme and navigation bars of the Web site. The Limited Access permission level cannot be customized or deleted.




Subscribe