public void AddEventRestriction(string eventId) { SPAuditEventType auditEventType; if (!eventId.TryParseEnum(true, out auditEventType)) { throw new JavaScriptException(this.Engine, "Error", "EventType parameter must be of the possible SPAuditEventTypes"); } m_auditQuery.AddEventRestriction(auditEventType); }
private void QueryButton_Click(object sender, EventArgs e) { SPSite site = new SPSite("http://sp2016"); SPAuditQuery query = new SPAuditQuery(site); query.AddEventRestriction(SPAuditEventType.View); query.RestrictToList(site.OpenWeb().Lists[0]); var collection = site.Audit.GetEntries(query); grid.DataSource = collection.Cast <SPAuditEntry>().ToList(); }
/// <summary> /// 查询数据绑定(使用sharepoint的API方法,放弃) /// </summary> protected void BindGrid() { if (String.IsNullOrEmpty(ListId)) { return; } DateTime dtS = DateTime.MinValue; if (!dateStart.IsDateEmpty) { dtS = dateStart.SelectedDate; } DateTime dtE = DateTime.MaxValue; if (!dateEnd.IsDateEmpty) { dtE = dateEnd.SelectedDate; } //获取当前选择用户的ID int userId=0; if (userPicker.ResolvedEntities.Count > 0) { PickerEntity pe = (PickerEntity)userPicker.ResolvedEntities[0]; userId = String.IsNullOrEmpty(pe.EntityData["SPUserID"]+"") ? Convert.ToInt32(pe.EntityData["SPUserID"] + "") : 0; //GetUserId(pe.Key); } //foreach (PickerEntity pe in userPicker.ResolvedEntities) //{ // string principalType = pe.EntityData["PrincipalType"].ToString(); // string loginName = pe.Key; //} SPSite siteColl = SPContext.Current.Site; SPWeb site = SPContext.Current.Web; SPSecurity.RunWithElevatedPrivileges( delegate() { using (SPSite ElevatedSiteCollection = new SPSite(siteColl.ID)) { using (SPWeb ElevatedSite = ElevatedSiteCollection.OpenWeb(site.ID)) { //取得列表 SPList list = ElevatedSite.Lists[new Guid(ListId)]; SPAuditQuery wssQuery = new SPAuditQuery(ElevatedSiteCollection); SPAuditEntryCollection auditCol; //SPList list = siteCollection.OpenWeb().Lists["公司共享文档"]; wssQuery.RestrictToList(list); //当是选择了某个文档库的某个文件的时候 if (!String.IsNullOrEmpty(ItemId)) { //获取该文档 SPListItem item = list.Items.GetItemById(Convert.ToInt32(ItemId)); wssQuery.RestrictToListItem(item); } #region 页面事件的查询条件 //判断页面的事件查询条件是否选择 bool isChecked = false; //添加选择的判断条件 foreach (ListItem item in cbHandle.Items) { if (item.Selected) { isChecked = true; if (item.Value.Equals("3")) { //查看 wssQuery.AddEventRestriction(SPAuditEventType.View); } else if (item.Value.Equals("5")) { //更新 wssQuery.AddEventRestriction(SPAuditEventType.Update); } else if (item.Value.Equals("4")) { //删除 wssQuery.AddEventRestriction(SPAuditEventType.Delete); } else if (item.Value.Equals("2")) { //签入 wssQuery.AddEventRestriction(SPAuditEventType.CheckIn); } else if (item.Value.Equals("1")) { //签出 wssQuery.AddEventRestriction(SPAuditEventType.CheckOut); } else if (item.Value.Equals("10")) { //从回收站还原 wssQuery.AddEventRestriction(SPAuditEventType.Undelete); } } } //当没选择事件的时候,默认添加以下条件 if (!isChecked) { //查看 wssQuery.AddEventRestriction(SPAuditEventType.View); //更新 wssQuery.AddEventRestriction(SPAuditEventType.Update); //删除 wssQuery.AddEventRestriction(SPAuditEventType.Delete); //签入 wssQuery.AddEventRestriction(SPAuditEventType.CheckIn); //签出 wssQuery.AddEventRestriction(SPAuditEventType.CheckOut); //从回收站还原 wssQuery.AddEventRestriction(SPAuditEventType.Undelete); } #endregion wssQuery.SetRangeStart(dtS); wssQuery.SetRangeEnd(dtE); if (userId != 0) { wssQuery.RestrictToUser(userId); } auditCol = ElevatedSiteCollection.Audit.GetEntries(wssQuery); //List<SPAuditEntry> data = new List<SPAuditEntry>(); //foreach (SPAuditEntry item in auditCol) //{ // item.ItemType=SPAuditItemType.Document // data.Add(item); //} this.AspNetPager1.PageIndex = PageIndex; AspNetPager1.PageSize = PageSize; AspNetPager1.RecordCount = auditCol.Count; this.gvData.DataSource = auditCol; this.gvData.DataBind(); // enumerate through audit log and read entries } } }); }
// POST api/values public SPAuditEntryCollection Post([FromBody] auditParam param) { using (SPSite site = new SPSite(param.siteUrl)) { using (SPWeb web = site.OpenWeb()) { // query SPAuditQuery query = new SPAuditQuery(site); // filters if (param.rowLimit != 0) { query.RowLimit = param.rowLimit; } // list and item if (param.listTitle != null) { SPList list = web.Lists[param.listTitle]; query.RestrictToList(list); if (param.itemId != 0) { SPListItem item = list.GetItemById(param.itemId); query.RestrictToListItem(item); } } // single user if (param.userId != 0) { query.RestrictToUser(param.userId); } // start and end times if (param.RangeStart != null) { DateTime start = Convert.ToDateTime(param.RangeStart); query.SetRangeStart(start); } if (param.RangeEnd != null) { DateTime end = Convert.ToDateTime(param.RangeEnd); query.SetRangeEnd(end); } // filter event types if (param.SPAuditEventType != null) { foreach (string s in param.SPAuditEventType) { if (s == "AuditMaskChange") { SPAuditEventType type = SPAuditEventType.AuditMaskChange; query.AddEventRestriction(type); } if (s == "CheckIn") { SPAuditEventType type = SPAuditEventType.CheckIn; query.AddEventRestriction(type); } if (s == "CheckOut") { SPAuditEventType type = SPAuditEventType.CheckOut; query.AddEventRestriction(type); } if (s == "ChildDelete") { SPAuditEventType type = SPAuditEventType.ChildDelete; query.AddEventRestriction(type); } if (s == "ChildMove") { SPAuditEventType type = SPAuditEventType.ChildMove; query.AddEventRestriction(type); } if (s == "Copy") { SPAuditEventType type = SPAuditEventType.Copy; query.AddEventRestriction(type); } if (s == "Custom") { SPAuditEventType type = SPAuditEventType.Custom; query.AddEventRestriction(type); } if (s == "Delete") { SPAuditEventType type = SPAuditEventType.Delete; query.AddEventRestriction(type); } if (s == "EventsDeleted") { SPAuditEventType type = SPAuditEventType.EventsDeleted; query.AddEventRestriction(type); } if (s == "FileFragmentWrite") { SPAuditEventType type = SPAuditEventType.FileFragmentWrite; query.AddEventRestriction(type); } if (s == "Move") { SPAuditEventType type = SPAuditEventType.Move; query.AddEventRestriction(type); } if (s == "ProfileChange") { SPAuditEventType type = SPAuditEventType.ProfileChange; query.AddEventRestriction(type); } if (s == "SchemaChange") { SPAuditEventType type = SPAuditEventType.SchemaChange; query.AddEventRestriction(type); } if (s == "Search") { SPAuditEventType type = SPAuditEventType.Search; query.AddEventRestriction(type); } if (s == "SecGroupCreate") { SPAuditEventType type = SPAuditEventType.SecGroupCreate; query.AddEventRestriction(type); } if (s == "SecGroupDelete") { SPAuditEventType type = SPAuditEventType.SecGroupDelete; query.AddEventRestriction(type); } if (s == "SecGroupMemberAdd") { SPAuditEventType type = SPAuditEventType.SecGroupMemberAdd; query.AddEventRestriction(type); } if (s == "SecGroupMemberDel") { SPAuditEventType type = SPAuditEventType.SecGroupMemberDel; query.AddEventRestriction(type); } if (s == "SecRoleBindBreakInherit") { SPAuditEventType type = SPAuditEventType.SecRoleBindBreakInherit; query.AddEventRestriction(type); } if (s == "SecRoleBindInherit") { SPAuditEventType type = SPAuditEventType.SecRoleBindInherit; query.AddEventRestriction(type); } if (s == "SecRoleBindUpdate") { SPAuditEventType type = SPAuditEventType.SecRoleBindUpdate; query.AddEventRestriction(type); } if (s == "SecRoleDefBreakInherit") { SPAuditEventType type = SPAuditEventType.SecRoleDefBreakInherit; query.AddEventRestriction(type); } if (s == "SecRoleDefCreate") { SPAuditEventType type = SPAuditEventType.SecRoleDefCreate; query.AddEventRestriction(type); } if (s == "SecRoleDefDelete") { SPAuditEventType type = SPAuditEventType.SecRoleDefDelete; query.AddEventRestriction(type); } if (s == "SecRoleDefModify") { SPAuditEventType type = SPAuditEventType.SecRoleDefModify; query.AddEventRestriction(type); } if (s == "Undelete") { SPAuditEventType type = SPAuditEventType.Undelete; query.AddEventRestriction(type); } if (s == "Update") { SPAuditEventType type = SPAuditEventType.Update; query.AddEventRestriction(type); } if (s == "View") { SPAuditEventType type = SPAuditEventType.View; query.AddEventRestriction(type); } if (s == "Workflow") { SPAuditEventType type = SPAuditEventType.Workflow; query.AddEventRestriction(type); } } } // download events SPAuditEntryCollection coll = site.Audit.GetEntries(query); return(coll); } } }