<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Arcobjects change table data source in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/arcobjects-change-table-data-source/m-p/663703#M17802</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Jon,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for posting this.&amp;nbsp; Could you also post the code you used for changing the datasource for featurelayers and raster??&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 25 Sep 2015 19:53:34 GMT</pubDate>
    <dc:creator>BBulla</dc:creator>
    <dc:date>2015-09-25T19:53:34Z</dc:date>
    <item>
      <title>Arcobjects change table data source</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/arcobjects-change-table-data-source/m-p/663701#M17800</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm writing a C# addin to change all the data sources in an MXD from one SDE datasource to another. I can iterate through the layers and change feature layers and raster layers, but what about tables?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There is very little doc on this - it can be done in &lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/TableView/00s300000017000000/"&gt;arcpy&lt;/A&gt;, but I could only find one old &lt;A href="http://forums.esri.com/Thread.asp?c=93&amp;amp;f=1742&amp;amp;t=238337"&gt;unanswered question&lt;/A&gt; for how to do it in arcobjects.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've used the &lt;A href="http://resources.arcgis.com/en/help/arcobjects-net/conceptualhelp/index.html#/d/000100000pqv000000.htm"&gt;TableCollection &lt;/A&gt;to iterate through the tables in the map, but it's not clear how to update the source for each one. Any ideas?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Mar 2015 11:42:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/arcobjects-change-table-data-source/m-p/663701#M17800</guid>
      <dc:creator>JonMorris2</dc:creator>
      <dc:date>2015-03-13T11:42:19Z</dc:date>
    </item>
    <item>
      <title>Re: Arcobjects change table data source</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/arcobjects-change-table-data-source/m-p/663702#M17801</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Anyone? Never mind, I've figured it out:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp; // focus map&lt;/SPAN&gt;
&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp; IMap map = ...&lt;/SPAN&gt;
&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp; // new data source for table&lt;/SPAN&gt;
&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp; IFeatureWorkspace workspace = ...&lt;/SPAN&gt;

&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp; ITableCollection tableCollection = (ITableCollection)map;&lt;/SPAN&gt;
&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp; List&amp;lt;ITable&amp;gt; tables = new List&amp;lt;ITable&amp;gt;();&lt;/SPAN&gt;
&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp; for (int i = 0; i &amp;lt; tableCount; i++)&lt;/SPAN&gt;
&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp; {&lt;/SPAN&gt;
&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp; tables.Add(tableCollection.get_Table(i));&lt;/SPAN&gt;
&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp; }&lt;/SPAN&gt;


&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp; // iterate over a copy of the tables so we can add and remove&lt;/SPAN&gt;
&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp; foreach (ITable oldTable in tables)&lt;/SPAN&gt;
&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp; {&lt;/SPAN&gt;
&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp; IDataset dataset = (IDataset)oldTable;&lt;/SPAN&gt;
&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp; IDatasetName datasetName = (IDatasetName)dataset.FullName;&lt;/SPAN&gt;


&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp; // assumes table name is same in new data source&lt;/SPAN&gt;


&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp; // get the new table&lt;/SPAN&gt;
&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp; ITable newTable = workspace.OpenTable(datasetName);&lt;/SPAN&gt;


&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp; // replace the table in the TOC&lt;/SPAN&gt;
&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp; ITableCollection tableCollection = (ITableCollection)map;&lt;/SPAN&gt;
&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp; tableCollection.RemoveTable(oldTable);&lt;/SPAN&gt;
&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp; tableCollection.AddTable(newTable);&lt;/SPAN&gt;


&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp; // fire change event to change table&lt;/SPAN&gt;
&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp; IMapAdmin2 mapAdmin2 = (IMapAdmin2)map;&lt;/SPAN&gt;
&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp; mapAdmin2.FireChangeTable(oldTable, newTable);&lt;/SPAN&gt;
&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp; }&lt;/SPAN&gt;


&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp; // Redraw the map&lt;/SPAN&gt;
&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp; IActiveView activeView = (IActiveView)map;&lt;/SPAN&gt;
&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp; activeView.Refresh();&lt;/SPAN&gt;


&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp; // Refresh TOC&lt;/SPAN&gt;
&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp; ESRI.ArcGIS.ArcMapUI.IContentsView contentsView = ArcMap.Document.CurrentContentsView;&lt;/SPAN&gt;
&lt;SPAN style="font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp; contentsView.Refresh(null);&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 04:03:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/arcobjects-change-table-data-source/m-p/663702#M17801</guid>
      <dc:creator>JonMorris2</dc:creator>
      <dc:date>2021-12-12T04:03:29Z</dc:date>
    </item>
    <item>
      <title>Re: Arcobjects change table data source</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/arcobjects-change-table-data-source/m-p/663703#M17802</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Jon,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for posting this.&amp;nbsp; Could you also post the code you used for changing the datasource for featurelayers and raster??&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Sep 2015 19:53:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/arcobjects-change-table-data-source/m-p/663703#M17802</guid>
      <dc:creator>BBulla</dc:creator>
      <dc:date>2015-09-25T19:53:34Z</dc:date>
    </item>
    <item>
      <title>Re: Arcobjects change table data source</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/arcobjects-change-table-data-source/m-p/663704#M17803</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There's a snippet &lt;A href="http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/Set_Data_Source_Snippet/00490000002r000000/" rel="nofollow noopener noreferrer" target="_blank"&gt;here&lt;/A&gt; that can change feature layer data source. The key thing is to call FireChangeFeatureClass after you've made the change to make sure the map is updated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;// Change FeatureClass of layer
&amp;nbsp; featureLayer.FeatureClass = newFeatureClass;
&amp;nbsp; mapAdmin2.FireChangeFeatureClass(oldFeatureClass, newFeatureClass);&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 04:03:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/arcobjects-change-table-data-source/m-p/663704#M17803</guid>
      <dc:creator>JonMorris2</dc:creator>
      <dc:date>2021-12-12T04:03:31Z</dc:date>
    </item>
  </channel>
</rss>

