<?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 Remove a join programmatically with C# in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/remove-a-join-programmatically-with-c/m-p/593060#M15958</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Due to a bug in arcpy (removing a join between an SDE-featureclass and an ODBC-table fails) I was forced to make an add-in with C# in order to remove the join for many layers in a Mapdocument. After hourses of searching for a solution and messing around with RelationShipClass, I found a usefull example in the VBA-documentation (&lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/sdk/10.0/vba_desktop/conceptualhelp/index.html#/How_to_remove_the_last_join_from_a_layer_or_table_in_ArcMap/00010000007s000000/" rel="nofollow noopener noreferrer" target="_blank"&gt;http://help.arcgis.com/en/sdk/10.0/vba_desktop/conceptualhelp/index.html#/How_to_remove_the_last_join_from_a_layer_or_table_in_ArcMap/00010000007s000000/&lt;/A&gt;&lt;SPAN&gt;). So, if someone is having the same problem, here is the solution:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
ESRI.ArcGIS.ArcMapUI.IMxDocument mxDocument = ArcMap.Application.Document as ESRI.ArcGIS.ArcMapUI.IMxDocument; // Dynamic Cast
ESRI.ArcGIS.Carto.IActiveView actView = mxDocument.ActiveView;
IMap focMap = actView.FocusMap;

for (int i = 0; i &amp;lt; focMap.LayerCount; i++)
{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IFeatureLayer2 actFeatLyr = focMap.get_Layer(i) as IFeatureLayer2;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ITable actLyr = focMap.get_Layer(i) as ITable;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IDisplayTable actDispTable = actFeatLyr as IDisplayTable;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IRelQueryTable actQueryTable = actDispTable.DisplayTable as IRelQueryTable;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IDisplayRelationshipClass actDispRelClass = actFeatLyr as IDisplayRelationshipClass;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; actDispRelClass.DisplayRelationshipClass(null, esriJoinType.esriLeftInnerJoin);
}
//Refreshing the view
actView.Refresh();

//Refreshing the TOC
ESRI.ArcGIS.ArcMapUI.IContentsView contentsView = mxDocument.CurrentContentsView;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; contentsView.Refresh(null);&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 01:28:16 GMT</pubDate>
    <dc:creator>DietmarPalmetzhofer</dc:creator>
    <dc:date>2021-12-12T01:28:16Z</dc:date>
    <item>
      <title>Remove a join programmatically with C#</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/remove-a-join-programmatically-with-c/m-p/593060#M15958</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Due to a bug in arcpy (removing a join between an SDE-featureclass and an ODBC-table fails) I was forced to make an add-in with C# in order to remove the join for many layers in a Mapdocument. After hourses of searching for a solution and messing around with RelationShipClass, I found a usefull example in the VBA-documentation (&lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/sdk/10.0/vba_desktop/conceptualhelp/index.html#/How_to_remove_the_last_join_from_a_layer_or_table_in_ArcMap/00010000007s000000/" rel="nofollow noopener noreferrer" target="_blank"&gt;http://help.arcgis.com/en/sdk/10.0/vba_desktop/conceptualhelp/index.html#/How_to_remove_the_last_join_from_a_layer_or_table_in_ArcMap/00010000007s000000/&lt;/A&gt;&lt;SPAN&gt;). So, if someone is having the same problem, here is the solution:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
ESRI.ArcGIS.ArcMapUI.IMxDocument mxDocument = ArcMap.Application.Document as ESRI.ArcGIS.ArcMapUI.IMxDocument; // Dynamic Cast
ESRI.ArcGIS.Carto.IActiveView actView = mxDocument.ActiveView;
IMap focMap = actView.FocusMap;

for (int i = 0; i &amp;lt; focMap.LayerCount; i++)
{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IFeatureLayer2 actFeatLyr = focMap.get_Layer(i) as IFeatureLayer2;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ITable actLyr = focMap.get_Layer(i) as ITable;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IDisplayTable actDispTable = actFeatLyr as IDisplayTable;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IRelQueryTable actQueryTable = actDispTable.DisplayTable as IRelQueryTable;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IDisplayRelationshipClass actDispRelClass = actFeatLyr as IDisplayRelationshipClass;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; actDispRelClass.DisplayRelationshipClass(null, esriJoinType.esriLeftInnerJoin);
}
//Refreshing the view
actView.Refresh();

//Refreshing the TOC
ESRI.ArcGIS.ArcMapUI.IContentsView contentsView = mxDocument.CurrentContentsView;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; contentsView.Refresh(null);&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:28:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/remove-a-join-programmatically-with-c/m-p/593060#M15958</guid>
      <dc:creator>DietmarPalmetzhofer</dc:creator>
      <dc:date>2021-12-12T01:28:16Z</dc:date>
    </item>
  </channel>
</rss>

