In this article, we are going to see the steps required to enforce unique value for SharePoint columns using C#. You can enforce uniqueness on values for SharePoint list or library columns. If you enforce a Person or Group column, the list item in the target list cannot have the same Person or Group on a child list.
You can enforce unique columns only to the below-supported columns types. They are,
- Person or Group (but not multi-value)
- Title (but not in a document library)
- Choice field (but not multi-choice)
- Number
- Lookup (but not multi-value)
- Currency
- Date/ Time
And the unsupported column types are,
- Multiple lines of text
- Custom Field Types
- Boolean (yes/no)
- Modified time
- UI version
- Created time
- Checked out to
- Calculated Field
- Modified by
- Content type ID
- Hyperlink/Picture
Step 1
Open Visual Studio, go to File -> New -> and select Project.

Step 2
In Templates, select Visual C#, select Console App (.NET Framework) and give an appropriate name in name textbox and then click the OK button.

Step 3
Steps to take are: Install SharePoint PnP Core Library in the C# project for indexing SharePoint field operations at the SharePoint site. The following blog can be referenced for installing the library. How To Install SharePoint PnP Core Library In Visual Studio 2017
After installing SharePoint core library, you can see the Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client.Runtime.dll in your project reference.

Step 4
Open the program.cs file and type the below code.




Join the conversation! Your thoughts help the community grow.