Programmatically Set a Text Field Default Value

Just a quick code snippet on setting the Default Text Value of a Single Line of Text field in SharePoint to a specific value.

   1: // update Shared Documents list "Customer Name" field
   2: SPList repDocs = childWeb.Lists["Shared Documents"];
   3: SPField clientName = repDocs.Fields["Customer Name"];
   4: clientName.DefaultValue = "foo";
   5: clientName.Update();


About Geoff Varosky
Geoff Varosky is a Senior Architect for Insight, based out of Watertown, MA. He has been architecting and developing web based applications his entire career, and has been working with SharePoint for the past 15 years. Geoff is an active member of the SharePoint community, Co-Founder and Co-Organizer of the Boston Area SharePoint Users Group, co-founder for the Boston Office 365 Users Group, co-organizer for SharePoint Saturday Boston and speaks regularly at SharePoint events and user groups.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: