using
System;
System.Collections.Generic;
System.Linq;
System.Text;
Microsoft.SharePoint;
namespace
EnforceUniqueness
{
class
Program
static
void
Main(
string
[] args)
try
Console.WriteLine(
"This tool will apply unique value constratint to a column in a list. Make sure that your list does not contain duplicate values in this column"
);
"\n"
"Enter the URL of Your Site"
String siteUrl = Console.ReadLine();
"Enter the Name of List name"
String listName = Console.ReadLine();
"Enter the Column Name"
String columnName = Console.ReadLine();
(SPSite site =
new
SPSite(siteUrl))
SPWeb web = site.OpenWeb();
SPList list = web.Lists[listName];
SPField field = list.Fields[columnName];
field.Indexed =
true
;
field.EnforceUniqueValues =
field.Update();
"Tool Executed successfully. Press Enter to Terminate"
Console.ReadLine();
}
catch
(Exception e)
Console.WriteLine(e.Message +
+ e.StackTrace);
Richard Mueller edited Revision 1. Comment: Removed tag "SPS 2010", added tag