InstructionsCreate a c# Console Application in Visual Studio, add a reference to Microsoft.SharePoint, and then add the following code to Program.cs. This will work with SharePoint 2007 and 2010 as long as you reference the correct assembly. Don’t forget to make sure your Visual Studio project’s Platform Target is Any CPU or x64.
using System; using System.IO; using System.Text; using System.Windows.Forms; using Microsoft.SharePoint; using Microsoft.SharePoint.Administration; namespace SPCheckAudit { class Program { [STAThread] static void Main(string[] args) { StringBuilder sb = new StringBuilder(); sb.Append("SiteID,SiteURL,ContentDB,"); foreach (int value in System.Enum.GetValues(typeof(SPAuditMaskType))) { sb.Append(System.Enum.GetName(typeof(SPAuditMaskType), value) + ","); } sb.Append("\r\n"); try { SPServiceCollection services = SPFarm.Local.Services; foreach (SPService curService in services) { if (curService is SPWebService) { SPWebService webService = (SPWebService)curService; foreach (SPWebApplication spWebApplication in webService.WebApplications) { foreach (SPSite site in spWebApplication.Sites) { if (site.Audit.AuditFlags != SPAuditMaskType.None) { sb.Append(site.ID + "," + site.Url + "," + site.ContentDatabase.Name + ","); int enumLength = System.Enum.GetValues(typeof(SPAuditMaskType)).Length - 1; int counter = 0; foreach (int value in System.Enum.GetValues(typeof(SPAuditMaskType))) { sb.Append(((site.Audit.AuditFlags & (SPAuditMaskType)value) == (SPAuditMaskType)value).ToString()); if (enumLength != counter) { sb.Append(","); } counter++; } sb.Append("\r\n"); } } } } } } catch (Exception ex) { sb.Append(ex.ToString()); } SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "CSV File|*.csv"; sfd.Title = "Save File"; if (sfd.ShowDialog() == DialogResult.OK) { using (var writer = new StreamWriter(sfd.FileName, true)) { writer.WriteLine(sb.ToString()); } } } } }
No comments:
Post a Comment