跟踪用户是否已阅读Sharepoint 2010文档中心的文档

跟踪用户是否已阅读Sharepoint 2010文档中心的文档,sharepoint,sharepoint-2010,document,receipt,user-tracking,Sharepoint,Sharepoint 2010,Document,Receipt,User Tracking,我想跟踪用户是否已阅读sharepoint 2010 document center的文档,当前用户信息未存储在审核日志中,是否有方法执行此操作?它将存储在审核日志中。 启用该特定文档库的审核,然后使用以下代码获取详细信息: SPSite oSPsite = new SPSite SPList doclib= oSPWeb.Lists["doclib"]; SPWeb oSPWeb = oSPsite.OpenWeb() SPListItemCollection doclibitems= doc

我想跟踪用户是否已阅读sharepoint 2010 document center的文档,当前用户信息未存储在审核日志中,是否有方法执行此操作?

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

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
     }
   }
       }

我找到了解决办法。这是步骤

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

    }
void context\u PreRequestHandlerExecute(对象发送方,事件参数e)
{
SPSecurity.runWithLevelatedPrivileges(委托()
{
var app=发送方作为HttpApplication;
如果(应用程序!=null)
{
string requesturl=app.Request.Url.ToString();
string file=string.Empty;
//如果文档在浏览器中打开
if(app.Request.QueryString[“Source”!=null&&app.Request.QueryString[“id”!=null&&app.Request.QueryString[“Source”].StartsWith(documentSiteUrl))
{
file=app.Request.QueryString[“id”]。删除(0,app.Request.QueryString[“id”]。LastIndexOf(“/”);
工人(档案);
}
//如果文档打开了已安装的office应用程序或下载了文档
if(requesturl.StartsWith(SiteUrl))
{
requesturl=requesturl.Remove(0,requesturl.LastIndexOf('/')+1);
工作者(请求URL);
}
}
});
}
私有void Worker(字符串requesturl)
{
#区域扩展控制
List extList=新列表(Exts.Split(“;”);
布尔结果=假;
foreach(extList中的字符串项)
{
if(requesturl.EndsWith(项目))
{
结果=真;
打破
}
}
#端区
if((!requesturl.Contains(“.aspx”)&&(!requesturl.EndsWith(“/”)&&result)
{
SPWeb web=SPContext.Current.web;
字符串文件名=requesturl.Substring(requesturl.LastIndexOf(“/”)+1);
//添加日志
web.AllowUnsafeUpdates=true;
AddReadInfo(web.CurrentUser,文件名,web);
web.AllowUnsafeUpdates=false;
}
}
私有void AddReadInfo(SPUser SPUser,字符串文件名,SPWeb)
{
#区域测井
SPList logList=web.Lists.TryGetList(“logList”);
如果(日志列表!=null)
{
SPListItem=logList.Items.Add();
项目[“用户”]=sPUser.Name;
项目[“文件”]=文件名;
项目[“已读”]=“已读”;
item.Update();
}
#端区
}
6-别忘了在项目上签字

7-建设项目

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

9-打开IIS管理器

10-找到你的站点并点选

11-开放模块

12-在模块页面下单击鼠标右键,然后选择添加托管模块选项

13-在dropdownlist下提供名称并选择您的模块


14-IIS重置。

如何为特定库启用审核?我找不到,对不起。它仅对同样在同一代码中的视图项启用审核。尝试使用上面的代码。它可能会起作用