0

Can any one let me know what's the issue in my below code and how can I solve this

SPSite mysiteCollection = new SPSite(SPContext.Current.Site.ID);
         SPWeb web = mysiteCollection.OpenWeb();
         web.AllowUnsafeUpdates = true;
         SPAuditQuery query = new SPAuditQuery(mysiteCollection);
                   query.SetRangeStart(DateTime.Now.AddDays(-1));
                   query.SetRangeEnd(DateTime.Now);
                   SPAuditEntryCollection auditCol = mysiteCollection.Audit.GetEntries(query);

                   int i = 0;
                   foreach (SPAuditEntry entry in auditCol)
                   {
                       if (entry.Event == SPAuditEventType.Update)
                       {

                           GridView1.DataSource = entry.EventName;
                           GridView1.DataBind();

                       }
                   }
1

Try this:

 using (SPSite mysiteCollection = new SPSite(SPContext.Current.Site.ID))
 {
        using (SPWeb oWeb = mysiteCollection.OpenWeb())
        {
             SPAuditQuery query = new SPAuditQuery(mysiteCollection);
             query.SetRangeStart(DateTime.Now.AddDays(-1));
             query.SetRangeEnd(DateTime.Now);
             SPAuditEntryCollection auditCol = mysiteCollection.Audit.GetEntries(query);

             DataTable dtAudit = new DataTable();
             dtAudit.Columns.Add("NewColumn", typeof(System.String));
             dtAudit.Columns.Add("NewColumnTwo", typeof(System.String));

             foreach (SPAuditEntry entry in auditCol)
             {
                  if (entry.Event == SPAuditEventType.Update)
                  {
                      DataRow dRow = dtAudit.Rows.Add();

                      dRow["NewColumn"] = entry.MachineName;
                      //dRow["NewColumnTwo"] = "TEXT";

                      dtAudit.Rows.Add(dRow);
                  }
              }

              GridView1.DataSource = dtAudit;
              GridView1.DataBind();
        }
  }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.