0

我想跟踪用户是否阅读了sharepoint 2010文档中心的文档,目前用户信息没有存储在审核日志中,有什么办法吗?

4

2 回答 2

0

它存储在审计日志中。启用对该特定文档库的审核,然后使用以下代码获取详细信息:

SPSite oSPsite = new SPSite
SPList doclib= oSPWeb.Lists["doclib"];
SPWeb oSPWeb = oSPsite.OpenWeb()
SPListItemCollection doclibitems= doclib.Items; 
foreach (SPListItem odoclibItem in doclibitems)
                        { 
odoclibItem .Audit.AuditFlags = SPAuditMaskType.View;
                        //    odoclibItem .Audit.AuditFlags = SPAuditMaskType
                            SPAuditQuery oquery = new SPAuditQuery(oSPsite);
                            oquery.RestrictToListItem(odoclibItem );
                            odoclibItem .Audit.Update();                        
                            SPAuditEntryCollection oAuditEntryCollection =SPsite.Audit.GetEntries(oquery);
                            foreach (SPAuditEntry entry in oAuditEntryCollection)
                            {
     if (entry.Event == SPAuditEventType.View)
    {
    id = Convert.ToString(entry.UserId);
     // get the user name and other details here
     }
   }
       }
于 2013-07-10T12:10:22.530 回答
0

我找到了解决方案。这是步骤。

1-创建一个类库。

2-右键单击库并添加新项目。

3- 在 Web 节点下选择 ASP.NET 模块。

4- 在 Init 中添加 PreRequestHandlerExecute 事件处理程序。这是我的代码。

public void Init(HttpApplication context)    
{
   context.PreRequestHandlerExecute += context_PreRequestHandlerExecute;
}

5- 方法

    void context_PreRequestHandlerExecute(object sender, EventArgs e)
    {
        SPSecurity.RunWithElevatedPrivileges(delegate()
        {
            var app = sender as HttpApplication;
            if (app != null)
            {
                string requesturl = app.Request.Url.ToString();
                string file = string.Empty;
                // if document opens in browser
                if (app.Request.QueryString["Source"] != null && app.Request.QueryString["id"] != null && app.Request.QueryString["Source"].StartsWith(documentSiteUrl))
                {
                    file = app.Request.QueryString["id"].Remove(0, app.Request.QueryString["id"].LastIndexOf('/'));
                    Worker(file);
                }
                // if document opened installed office apps or downloaded the document
                if (requesturl.StartsWith(SiteUrl))
                {
                    requesturl = requesturl.Remove(0, requesturl.LastIndexOf('/') + 1);
                    Worker(requesturl);
                }
            }
        });

    }

    private void Worker(string requesturl)
    {

        #region ext control
        List<string> extList = new List<string>(Exts.Split(';'));
        bool result = false;
        foreach (string item in extList)
        {
            if (requesturl.EndsWith(item))
            {
                result = true;
                break;
            }
        }
        #endregion

        if ((!requesturl.Contains(".aspx")) && (!requesturl.EndsWith("/")) && result)
        {
            SPWeb web = SPContext.Current.Web;

            String fileName = requesturl.Substring(requesturl.LastIndexOf("/") + 1);

            // Add log
            web.AllowUnsafeUpdates = true;
            AddReadInfo(web.CurrentUser, fileName, web);
            web.AllowUnsafeUpdates = false;
        }
    }

    private void AddReadInfo(SPUser sPUser, string fileName, SPWeb web)
    {

        #region Logging

            SPList logList = web.Lists.TryGetList("LogList");
            if (logList != null)
            {
                SPListItem item = logList.Items.Add();
                item["User"] = sPUser.Name;
                item["Document"] = fileName;
                item["Read"] = "Read";
                item.Update();

            }

        #endregion

    }

6-不要忘记签署项目。

7-构建项目。

8- 将 dll 添加到 C:\inetpub\wwwroot\wss\VirtualDirectories\80\ 文件夹下的 GAC 和 BIN 文件夹。

9- 打开 IIS 管理器。

10-找到您的站点点头并选择。

11- 打开模块。

12- 在模块页面下右键单击并选择添加托管模块选项。

13- 命名并在下拉列表下选择您的模块。

14- IIS 重置。

于 2013-07-11T11:46:25.570 回答