# Add column to .shp, populate and save

**URL:** <https://community.thinkgeo.com/t/add-column-to-shp-populate-and-save/488>\
**Category:** WinForms\
**Created:** [June 22, 2009, 3:24am UTC](https://community.thinkgeo.com/t/add-column-to-shp-populate-and-save/488 "2009-06-22T03:24:55Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Patrick](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/p/b2d939/32.png) [@Patrick](https://community.thinkgeo.com/u/Patrick)\
**Post date:** [June 22, 2009, 3:24am UTC](https://community.thinkgeo.com/t/add-column-to-shp-populate-and-save/488/1 "2009-06-22T03:24:55Z")

</div>

Hello

I&nbsp;found&nbsp;lots&nbsp;of&nbsp;threads&nbsp;related&nbsp;to&nbsp;this&nbsp;but&nbsp;no&nbsp;convenient&nbsp;solution&nbsp;for&nbsp;me.

I&nbsp;was&nbsp;using&nbsp;API&nbsp;2.0&nbsp;DBaseFile&nbsp;and&nbsp;I&nbsp;need&nbsp;a&nbsp;3.x&nbsp;equivalent&nbsp;now...&nbsp;that&nbsp;I&nbsp;do&nbsp;not&nbsp;find.

I&nbsp;need&nbsp;to:

1.&nbsp;open&nbsp;a&nbsp;shape&nbsp;file  
  
2.&nbsp;add&nbsp;a&nbsp;column  
  
3.&nbsp;populate&nbsp;this&nbsp;column  
  
4.&nbsp;save

Any&nbsp;idea&nbsp;?

Patrick.

---

<div class="post-metadata">

**Author:** ![ThinkGeo](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/thinkgeo/32/25029_2.png) [@ThinkGeo](https://community.thinkgeo.com/u/ThinkGeo)\
**Post date:** [June 22, 2009, 3:42am UTC](https://community.thinkgeo.com/t/add-column-to-shp-populate-and-save/488/2 "2009-06-22T03:42:45Z")

</div>

Patrick,&nbsp;

Thanks&nbsp;for&nbsp;your&nbsp;post!

I&nbsp;am&nbsp;not&nbsp;very&nbsp;clear&nbsp;about&nbsp;your&nbsp;third&nbsp;step&nbsp;“Populate&nbsp;this&nbsp;column”&nbsp;doing,&nbsp;following&nbsp;is&nbsp;some&nbsp;guide&nbsp;code&nbsp;you&nbsp;can&nbsp;take&nbsp;a&nbsp;reference:

`ShapeFileFeatureSource featureSource = new ShapeFileFeatureSource(shapeFileName, ShapeFileReadWriteMode.ReadWrite);featureSource.Open();featureSource.BeginTransaction();featureSource.AddColumnString("AddedFieldName", 10);TransactionResult result = featureSource.CommitTransaction();if (result.TotalFailureCount > 0){  throw new InvalidOperationException("Some operation failed!");}Collection<DbfColumn> addedColumns = featureSource.GetDbfColumns();featureSource.Close();`

If&nbsp;you&nbsp;have&nbsp;any&nbsp;more&nbsp;questions&nbsp;just&nbsp;do&nbsp;not&nbsp;hesitate&nbsp;to&nbsp;let&nbsp;me&nbsp;know.

Thanks.

Yale

---

<div class="post-metadata">

**Author:** ![ln1](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/l/a9a28c/32.png) [@ln1](https://community.thinkgeo.com/u/ln1)\
**Post date:** [May 30, 2012, 2:07am UTC](https://community.thinkgeo.com/t/add-column-to-shp-populate-and-save/488/3 "2012-05-30T02:07:31Z")

</div>

How&nbsp;to&nbsp;add&nbsp;column&nbsp;with&nbsp;values&nbsp;corresponding&nbsp;to&nbsp;already&nbsp;existing&nbsp;column&nbsp;values.

---

<div class="post-metadata">

**Author:** ![Gary2](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/g/49beb7/32.png) [@Gary2](https://community.thinkgeo.com/u/Gary2)\
**Post date:** [May 30, 2012, 1:55pm UTC](https://community.thinkgeo.com/t/add-column-to-shp-populate-and-save/488/4 "2012-05-30T13:55:23Z")

</div>

Hello&nbsp;In,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Can&nbsp;you&nbsp;describe&nbsp;more&nbsp;about&nbsp;your&nbsp;scenario?&nbsp;  
&nbsp;&nbsp;  
&nbsp;Regards,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Gary

---

<div class="post-metadata">

**Author:** ![ln1](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/l/a9a28c/32.png) [@ln1](https://community.thinkgeo.com/u/ln1)\
**Post date:** [June 15, 2012, 1:11am UTC](https://community.thinkgeo.com/t/add-column-to-shp-populate-and-save/488/5 "2012-06-15T01:11:59Z")

</div>

Actually&nbsp;my&nbsp;requirement&nbsp;is&nbsp;to&nbsp;color&nbsp;the&nbsp;country&nbsp;based&nbsp;on&nbsp;some&nbsp;numeric&nbsp;values.&nbsp;For&nbsp;example&nbsp;am&nbsp;having&nbsp;the&nbsp;numeric&nbsp;values&nbsp;corresponding&nbsp;to&nbsp;all&nbsp;the&nbsp;countries&nbsp;in&nbsp;the&nbsp;world&nbsp;and&nbsp;i&nbsp;have&nbsp;some&nbsp;range&nbsp;to&nbsp;color&nbsp;the&nbsp;country&nbsp;based&nbsp;on&nbsp;values.&nbsp;how&nbsp;can&nbsp;we&nbsp;achieve&nbsp;this&nbsp;in&nbsp;the&nbsp;simple&nbsp;and&nbsp;best&nbsp;way.&nbsp;I&nbsp;have&nbsp;achived&nbsp;this&nbsp;using&nbsp;Color&nbsp;based&nbsp;on&nbsp;values&nbsp;feature&nbsp;in&nbsp;our&nbsp;websamples.&nbsp;Is&nbsp;this&nbsp;the&nbsp;best&nbsp;way?

&nbsp;

---

<div class="post-metadata">

**Author:** ![Gary2](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/g/49beb7/32.png) [@Gary2](https://community.thinkgeo.com/u/Gary2)\
**Post date:** [June 15, 2012, 4:10pm UTC](https://community.thinkgeo.com/t/add-column-to-shp-populate-and-save/488/6 "2012-06-15T16:10:42Z")

</div>

Hello&nbsp;In,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks&nbsp;for&nbsp;your&nbsp;further&nbsp;information.&nbsp;  
&nbsp;&nbsp;  
&nbsp;If&nbsp;you&nbsp;have&nbsp;multiple&nbsp;countries&nbsp;in&nbsp;your&nbsp;shapefile&nbsp;and&nbsp;want&nbsp;to&nbsp;set&nbsp;the&nbsp;color&nbsp;of&nbsp;one&nbsp;specifically&nbsp;you&nbsp;will&nbsp;need&nbsp;to&nbsp;use&nbsp;our&nbsp;ValueStyle&nbsp;as&nbsp;demonstrated&nbsp;in&nbsp;the&nbsp;Samples&nbsp;-&nbsp;Styles&nbsp;-&nbsp;Draw&nbsp;Features&nbsp;Based&nbsp;on&nbsp;a&nbsp;Value&nbsp;sample.&nbsp;In&nbsp;this&nbsp;sample&nbsp;you&nbsp;will&nbsp;see&nbsp;a&nbsp;ValueStyle.ColumnValue.&nbsp;This&nbsp;ColumnValue&nbsp;is&nbsp;found&nbsp;in&nbsp;the&nbsp;dbf&nbsp;of&nbsp;your&nbsp;shapefile&nbsp;and&nbsp;the&nbsp;ValueStyle&nbsp;searches&nbsp;this&nbsp;column&nbsp;for&nbsp;a&nbsp;the&nbsp;value&nbsp;you&nbsp;specify&nbsp;and&nbsp;colors&nbsp;as&nbsp;necessary.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Regards,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Gary

---

<div class="post-metadata">

**Author:** ![ln1](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/l/a9a28c/32.png) [@ln1](https://community.thinkgeo.com/u/ln1)\
**Post date:** [January 21, 2013, 10:33pm UTC](https://community.thinkgeo.com/t/add-column-to-shp-populate-and-save/488/7 "2013-01-21T22:33:54Z")

</div>

Hi&nbsp;Gary,

Thanks&nbsp;for&nbsp;your&nbsp;support.

I&nbsp;need&nbsp;to&nbsp;color&nbsp;the&nbsp;countries&nbsp;(multiple&nbsp;countries)&nbsp;based&nbsp;on&nbsp;my&nbsp;own&nbsp;numerical&nbsp;values&nbsp;i.e&nbsp;i&nbsp;have&nbsp;values&nbsp;corresponding&nbsp;to&nbsp;countries.

In&nbsp;this&nbsp;Scenario&nbsp;shall&nbsp;we&nbsp;add&nbsp;our&nbsp;own&nbsp;new&nbsp;column&nbsp;in&nbsp;the&nbsp;dbf&nbsp;of&nbsp;our&nbsp;shape&nbsp;file&nbsp;so&nbsp;that&nbsp;ValueStyle&nbsp;searches&nbsp;this&nbsp;column&nbsp;(newly&nbsp;added&nbsp;column)&nbsp;for&nbsp;the&nbsp;value&nbsp;we&nbsp;specify&nbsp;and&nbsp;colors&nbsp;as&nbsp;necessary.

Kindly&nbsp;clarify&nbsp;on&nbsp;this.

Many&nbsp;Thanks.

---

<div class="post-metadata">

**Author:** ![Gary2](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/g/49beb7/32.png) [@Gary2](https://community.thinkgeo.com/u/Gary2)\
**Post date:** [January 23, 2013, 9:22pm UTC](https://community.thinkgeo.com/t/add-column-to-shp-populate-and-save/488/8 "2013-01-23T21:22:46Z")

</div>

Hello&nbsp;In,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Yes,&nbsp;that’s&nbsp;a&nbsp;good&nbsp;way&nbsp;if&nbsp;you&nbsp;can&nbsp;process&nbsp;all&nbsp;the&nbsp;data&nbsp;before&nbsp;you&nbsp;will&nbsp;use&nbsp;it.&nbsp;Also&nbsp;there&nbsp;is&nbsp;another&nbsp;way,&nbsp;you&nbsp;can&nbsp;refer–\>HowDoISamples–\>DataProviders–\>LoadAHeatLayer,&nbsp;in&nbsp;this&nbsp;sample,&nbsp;we&nbsp;use&nbsp;CustomColumnFetch&nbsp;which&nbsp;is&nbsp;a&nbsp;temporary&nbsp;column.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Regards,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Gary
