public void SetRangeEnd(DateInstance end)
        {
            if (end == null)
            {
                throw new JavaScriptException(this.Engine, "Error", "End date must be specified.");
            }

            m_auditQuery.SetRangeEnd(end.Value);
        }
Example #2
0
        // CheckOut,	CheckIn,	View,	Delete,	Update,	ProfileChange,	ChildDelete,
        // SchemaChange,	Undelete,	Workflow,	Copy,	Move,	AuditMaskChange,
        // Search,	ChildMove,	SecGroupCreate,	SecGroupDelete,	SecGroupMemberAdd,
        // SecGroupMemberDel,	SecRoleDefCreate,	SecRoleDefDelete,	SecRoleDefModify,	SecRoleDefBreakInherit,
        // SecRoleBindUpdate,	SecRoleBindInherit,	SecRoleBindBreakInherit,	EventsDeleted,	Custom

        protected void Page_Load(object sender, EventArgs e)
        {
            //string documentUrl = "http://spwfe03p-bro/sites/StaffPortal/TestWork1/Pages/Test.aspx";
            string documentUrl = "http://staffportal.myselfserve.com.au/sites/StaffPortal/TestWork1/Pages/Test-Bendigo-TAFE%E2%80%99s-2018-Apprentice-and-Industry-Awards.aspx";
            string siteUrl     = "http://spwfe03p-bro/sites/staffportal/TestWork1";
            //string listName = "Auditing Details";//"Pages";
            string listName = "Pages";
            SPList listObj;

            try
            {
                using (SPSite site = new SPSite(documentUrl))//siteUrl
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        string     DocLibName           = documentUrl.Substring(web.Url.Length + 1).Substring(0, documentUrl.Substring(web.Url.Length + 1).IndexOf("/"));
                        string     DocNameWithExtension = documentUrl.Substring(documentUrl.LastIndexOf("/") + 1);
                        string     DocName = DocNameWithExtension.Substring(0, DocNameWithExtension.LastIndexOf("."));
                        SPListItem itemObj = QueryListItem(web, DocLibName);
                        //listObj = (SPDocumentLibrary)web.Lists[listName];

                        //string s = web.Url;
                        //string a = documentUrl.Substring(web.Url.Length + 1, documentUrl.Length - web.Url.Length);    //  documentUrl.Substring(web.Url.Length + 1);

                        SPAuditQuery query = new SPAuditQuery(site);
                        //query.RestrictToList(listObj);
                        //query.RestrictToListItem(itemObj);
                        //query.AddEventRestriction(SPAuditEventType.View);
                        //query.AddEventRestriction(SPAuditEventType.Search);
                        query.SetRangeStart(DateTime.Now.AddDays(-15));
                        query.SetRangeEnd(DateTime.Now);
                        SPAuditEntryCollection auditCol = web.Audit.GetEntries(query);
                        foreach (SPAuditEntry audit in auditCol)
                        {
                            string   docName     = audit.DocLocation; // audit.DocLocation = documentUrl.Substring(documentUrl.LastIndexOf("/")+1)
                            int      userID      = audit.UserId;
                            string   userEmail   = (web.AllUsers.GetByID(audit.UserId)).Email;
                            string   userName    = (web.AllUsers.GetByID(audit.UserId)).Name;
                            string   ItemID      = Convert.ToString(audit.ItemId);
                            string   ItemType    = Convert.ToString(audit.ItemType);
                            string   EventType   = Convert.ToString(audit.Event);
                            DateTime OccuredDate = audit.Occurred;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //Catch error in to ULS log.
            }
        }
Example #3
0
        private void ProcessAuditLogReport()
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite site = new SPSite(SPContext.Current.Site.ID))
                {
                    using (SPWeb web = site.OpenWeb(SPContext.Current.Web.ID))
                    {
                        //limit query to a specific site
                        SPAuditQuery query = new SPAuditQuery(site);

                        //set the query date range
                        query.SetRangeStart(this.StartDate);
                        query.SetRangeEnd(this.EndDate);

                        SPAuditEntryCollection auditCol = web.Audit.GetEntries(query);
                        PrepareAuditReport(auditCol, web);
                    }
                }
            });
        }
Example #4
0
        /// <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
                  }
              }

              });
        }
Example #5
0
        // 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);
                }
            }
        }