locked
Document read count RRS feed

  • Question

  • I would like to display the number of times a document has been read in a document library! It should be one of the columns in the document library page. is it possible?
    Friday, December 10, 2010 4:45 AM

Answers

  • Hi,

    I can think couple of ways.

    1. You can configured the audit log with in the site collection.

     Go to site action-->Site Collection Audit settings--->Check teh first option and say OK.

    Now view something with in site and again go to site action--->Log Reports.

    2. You can use item level auditing which is provided by microsoft.

    http://msdn.microsoft.com/en-us/library/bb397403%28office.12%29.aspx

    3. you can use the object model and use SPAudit class.

    Hope this will help


    Cheers, Hemendra-MCTS "Yesterday is just a memory,Tomorrow we may never see"
    • Marked as answer by Emir Liu Thursday, December 16, 2010 3:12 AM
    Friday, December 10, 2010 8:21 AM
    Moderator

All replies

  • Hi,

    I can think couple of ways.

    1. You can configured the audit log with in the site collection.

     Go to site action-->Site Collection Audit settings--->Check teh first option and say OK.

    Now view something with in site and again go to site action--->Log Reports.

    2. You can use item level auditing which is provided by microsoft.

    http://msdn.microsoft.com/en-us/library/bb397403%28office.12%29.aspx

    3. you can use the object model and use SPAudit class.

    Hope this will help


    Cheers, Hemendra-MCTS "Yesterday is just a memory,Tomorrow we may never see"
    • Marked as answer by Emir Liu Thursday, December 16, 2010 3:12 AM
    Friday, December 10, 2010 8:21 AM
    Moderator
  • Hi,

     

    Follow below steps for getting number of views in a column (By intense R&D I was able to do that):

    1. Enable Auditing on the site collection in site settings.

    2. Add a column name "Views" to the libraries where you want to show it.

    3. Develop a Console application in VS2010 (On the sharepoint server) & target CPU As x64.

    4. Refer below code:

     

    class Program
        {
            static void Main(string[] args)
            {

                using (SPSite site = new SPSite("http://server/"))
                {
                    using (SPWeb web = site.RootWeb)
                    {
                        foreach (SPList list in web.Lists)
                        {
                            foreach (SPListItem item in list.Items)
                            {
                                if (item.Fields.ContainsField("Views"))
                                {
                                    SPAuditEntryCollection aucoll = item.Audit.GetEntries();
                                    item["Views"] = aucoll.Count;
                                    item.Update();
                                    Console.WriteLine("Success {0}", aucoll.Count);
                                }
                            }
                        }
                    }
                       
                   Console.ReadLine();               
                   
                }

            }

     

    You need to run above code on regular basis to update the data.

    It worked for me. Hope it helps!

    • Proposed as answer by Deepak K Singh Thursday, March 3, 2011 11:11 AM
    Thursday, January 20, 2011 1:40 PM