One way to implement click counters

Source: Internet
Author: User

Document Library Settings> Information Management Policy Settings> definition Policy> OK> enable review. If you need to click the number of times on the page, you can customize a field for statistics, custom fields are available in many places. I won't talk about it anymore. I used Audit to count the number of clicks on the entire website. I have mentioned the code 07 added to SPD on the Internet, I have never used 07, and I don't know how to fix it. In addition, many big brothers say that method is no longer usable. So I found Audit as prompted.

 

Because my pages are all publishing pages, you can imagine that I have all "pages" under the document library. First, I open the tracking record through the following code:

 

Using (SPSite site = new SPSite ("http: // sps2010 "))
{
SPList list = site. RootWeb. Lists ["page"];
List. Audit. AuditFlags = SPAuditMaskType. View;

List. Audit. Update ();

}

Of course, we can also enable it through the UI:

Document Library Settings> Information Management Policy Settings> definition Policy> OK> enable review

 

 

Then I use the following code for statistics:

 

Using (SPSite site = new SPSite ("http: // sps2010 "))
{
SPList list = site. RootWeb. Lists ["page"];
SPAuditQuery wssQuery = new SPAuditQuery (site );
SPAuditEntryCollection auditCol = list. Audit. GetEntries (wssQuery );

Int I = 1;
Foreach (SPAuditEntry item in auditCol)
{
Console. WriteLine (item. ItemType + "--" + I );
I ++;
}

}

 

 

Finally, you can calculate the number of times in the List based on item. ItemType.

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.