SharePoint 2013 Gets the number of document downloads through audits

Source: Internet
Author: User

1. Create a document library and enter the library settings. Find "Information management policy settings" and click to enter. For example, with:

2. Set "Document", "folder" two respectively. For example, with:

3, tick enable Auditing. For example, with:

4. Tick all the event, for example:

5, code. For example, the following:

 Public Static voidGetdownloadnum (stringUrlstringSiteURL) {Spsecurity.runwithelevatedprivileges (Delegate()    {        using(SPSite site =NewSPSite (SiteURL)) {            using(SPWeb Web =site. OpenWeb ()) {web. Allowunsafeupdates=true; Spauditquery Auditquery=NewSpauditquery (site);                Auditquery.addeventrestriction (Spauditeventtype.view); Auditquery.restricttolistitem (web. GetFile (URL).                Item); Spauditentrycollection auditentrycollection=web.                Audit.getentries (Auditquery);                Console.WriteLine (URL); Console.WriteLine ("Count:"+auditEntryCollection.Count.ToString ()); }        }    });}

6. Download a test document, execute the code, for example:

Summary

I've been hearing about the number of downloads of documents through audits. Try to feel good to use, but also see that there is a way to encapsulate their own definition of the field, or timerjob solution, feeling is a way of it, simple write open and call the way to everyone to participate in the test.

In particular, other event can be viewed in addition to the number of downloads. In addition to the audit information for list items, there is information about the list. You are interested in being able to try it yourself.

All right, here we go. Rest.

Have a rest ...

Documentation for references

Http://msdn.microsoft.com/en-us/library/bb466223.aspx

SharePoint 2013 Gets the number of document downloads through audits

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.