SharePoint 2010 Document Management: Number of clicks

Source: Internet
Author: User

In many scenarios, we all need to count the number of clicks on an article or document, but SharePoint itself does not design such a field, so we need to do this with simple field development.

First, create the project:

1. Create an empty SharePoint project, add a "SharePoint Map folder" and map it to Template/xml to hold the XML we described for the field.

2. Add an XML to the mapped XML folder, the name is Fldtypes_ field name, the previous name must be such a rule, will be recognized by SharePoint, XML template appended.

3. Add a VisitorRecord.cs file to inherit from the SPField field and add a VisitorRecordControl.cs file to inherit from Basefieldcontrol.

4. Project structure, as shown below:

Second, add code

1. Add XML description

<?xml version="1.0" encoding="utf-8" ?>
<FieldTypes>
<FieldType>
<Field Name="TypeName">VisitorRecord</Field>
<Field Name="ParentType">Text</Field>
<Field Name="TypeDisplayName">浏览次数</Field>
<Field Name="TypeShortDescription">每点击一次DispForm页,浏览次数+1</Field>
<Field Name="UserCreatable">TRUE</Field>
<Field Name="Sortable">TRUE</Field>
<Field Name="AllowBaseTypeRendering">TRUE</Field>
<Field Name="Filterable">TRUE</Field>
<Field Name="FieldTypeClass">VisitorRecord.VisitorRecord,VisitorRecord, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a3d395e8da16bea6</Field>
<RenderPattern Name="DisplayPattern">
<Column />
</RenderPattern>
</FieldType>
</FieldTypes>

2. Add Visitorrecord method, the following table:

class VisitorRecord : SPField
{
public VisitorRecord(SPFieldCollection fields, string fieldName)
: base(fields, fieldName)
{
Init();
}
public VisitorRecord(SPFieldCollection fields, string typeName, string displayName)
: base(fields, typeName, displayName)
{
Init();
}
void Init()
{
//设置在DisplayForm页显示
this.ShowInDisplayForm = true;
//设置在EditFrom页不显示
this.ShowInEditForm = false;
//在NewForm页不显示
this.ShowInNewForm = false;
}
public override BaseFieldControl FieldRenderingControl
{
get
{
BaseFieldControl vr1 = new VisitorRecordControl();
vr1.FieldName = this.InternalName;
return vr1;
}
}
}

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.