Freigeben über


By default, In the installation of WSS3.0 setup, you didn't get the Audit logs reports option. if you enable the logs using event handler , you will not get the view logs of items.

Create an HttpHandler using the ClassLibraryTemplate in the visual Studio 2005.

using System;

using System.Web;

using System.Collections.Generic;

using System.Text;

using Microsoft.SharePoint;

using Microsoft.SharePoint.ApplicationRuntime;

using Microsoft.SharePoint.Utilities;

using System.IO;

namespace [NameSpaceName]

{

public class [ClassName] :IHttpHandler

{

public [ClassName]()

{

}

public void ProcessRequest(HttpContext context)

{

SPFile myFile = null;

SPSite siteCollection = SPContext.Current.Site;

SPWeb web = siteCollection.OpenWeb();

web.AllowUnsafeUpdates = true;

SPList list = web.Lists["MyList"];

SPListItemCollection items = list.Items;

string URL = context.Request.Url.ToString();

Char[] param = { '/' };

String[] filename = URL.Split(param);

string path = "";

foreach (SPListItem item in items)

{

if (item.Name.ToUpper() == filename[filename.Length - 1].ToUpper().ToString())

{

item.Audit.WriteAuditEvent(SPAuditEventType.View, "CustomViewAuditEvent", "<myXml>MyData</myXml>");

item.Audit.AuditFlags = SPAuditMaskType.All;

item.Audit.Update();

myFile = item.File;

byte[] fileBuffer = myFile.OpenBinary();

path = "c:\\" + myFile.Name;

FileStream stream = new FileStream(path, FileMode.Create);

stream.Write(fileBuffer, 0, fileBuffer.Length);

stream.Close();

}

}

list.Audit.Update();

web.Update();

context.Response.WriteFile(path);

}

public bool IsReusable

{

// To enable pooling, return true here.

// This keeps the handler in memory.

get { return false; }

}

}

}

Comments