Developing Custom Field Type for Sharepoint 201

Source: Internet
Author: User
Tags visual studio 2010

The ECM features of SharePoint 2010 are excellent. the best thing is the extendibility of the platform using SharePoint designer and Visual Studio. by default SharePoint shortdes field types such as single line text, multi-line text etc. the following is the snapshot of the fields available in SharePoint 2010

The out of the box field controls are useful for most situations, but still you may need additional field types when building business applications. fortunately you can build custom field controls using Visual Studio 2010 and deploy to SharePoint. custom field control can provide a unique editing and display experience. custom field controls can be used to include custom client-side validation and a unique editing experience.

In this article I am going to demonstrate how you can build M field control for Sharepoint 2010. for the purpose of this article, I am going to build a custom field control that inherits the single line of text. when displaying the control, it will show the entered text in

Open Visual Studio, from the File menu select new project. In the new project dialog, select empty SharePoint project as the template. I have named the project as "mycustomfieldproject"

In the SharePoint customization wizard, make sure you select "deploy as farm solution". Also you can enter the local site URL where you can deploy the Custom field.

Click the finish button. Visual Studio will create an empty project. In Visual Studio Solution Explorer, the project looks as follows.

Now you need to add a class to the solution that represents the Custom field. Now right click the project and select Add-> class

I have named the class as "myheaderfield"

The class just created have the following code.

Now you need to set the class as public. you need to include the using statement to include Microsoft. sharepoint to get access to the SharePoint built in types. as I mentioned initially myheaderfield needs to inherit the SharePoint text field which is "spfieldtext ". now you need to override the 2 default construtors. after making the mentioned changes, the code file looks as follows.

Now I am going to override 2 methods as follows.

  • Getvalidatedstring-this will be used to validate the data before saving to database.
  • Getfieldvalueashtml-this is how the value will be displayed in the page.

The implementation of the methods are as follows.

Each field type you define showould have a corresponding entry in the form of XML file in the XML folder under 14 \ template folder. The XML file will have the following naming convention

  • It shoshould start with fldtypes _
  • After _ you can define the field name. It is a good practice to specify the class name as the field name, though it is not a must
  • In the XML file, you need to define the fields such as typename, parent type name, type display name, corresponding class and assembly.

Now in the Visual Studio project, you need to add a XML file and while deploying it shoshould be deployed to the folder 14 \ template \ XML. to do this, you can add a mapped folder to your project. right click the project in Solution Explorer, select Add-> SharePoint mapped folder

In the Add mapped folder dialog, expand template and select XML

Now you can see the XML folder under your project. any files created here will be deployed to the 14 \ template \ XML folder in the SharePoint farm where the solution is deployed. now you need to add the XML file for your field.

Right click the project, select Add-> new item. Now in the Template Selection, select data as the category and then select XML as the file type. I have named fldtypes_myheaderfield.xml

I have updated the content of the XML file as follows. be noted that $ Sharepoint. project. assemblyfullname $ will be replaced automatically by the correct assembly name wile deploying. all the other fields are self-explanatory.

Now we are done with all the requirements. From the Solution Explorer, right click the project and click deploy.

Once deployed, you can add new columns to SharePoint lists and libraries with the type "myheaderfield". Add the new column to SharePoint types will show the new type you added.

I have added a new column named "myheader" to my publishing page content type. Now when I try to add text to the column, it will validate it. See a simple Validation

SharePoint 2010 is extensible as you can build and deploy M fields that address your custom business requirements.

Published Sunday, February 05,201 2 AM by sreejukg

Filed under: Sharepoint, Sharepoint 2010, Visual Studio, C #, Visual Studio 2010 comments # developing Custom Field Type for Sharepoint 2010 | ASP. net | syngusunday, February 05,201 2 AM by developing Custom Field Type for Sharepoint 2010 | ASP. net | syngu

Pingback from developing Custom Field Type for Sharepoint 2010 | ASP. NET | syngu

# SharePoint 2010: recopilatorio de Enlaces interesantes (XXIX )! Wednesday, February 29,201 PM by blog del ciin

Aqu & Iacute; OS dejo la nueva Entrega del recopilatorio de Enlaces interesantes del mes pasado sobre SharePoint

# SharePoint 2010: recopilatorio de Enlaces interesantes (XXIX )! & Amp; laquo; Pasi ?? N por la tecnolog ?? A & #8230; Wednesday, February 29,201 2 pm by Sharepoint 2010: recopilatorio de Enlaces interesantes (XXIX )! «Pasi ?? N por la tecnolog ?? A...

Pingback from SharePoint 2010: recopilatorio de Enlaces intere

Resource: http://weblogs.asp.net/sreejukg/archive/2012/02/05/developing-custom-field-type-for-sharepoint-2010.aspx

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.