<?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: Cannot Open Shapefile in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/cannot-open-shapefile/m-p/139136#M3610</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi there,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hopefully if someone can explain how to open shape files in arcgis. Do I need to write code. Which code do I have to and where shall I write it exactly. Please I hope someone can help me.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks a million in advance.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 07 Jul 2011 14:14:48 GMT</pubDate>
    <dc:creator>WilliamSmith4</dc:creator>
    <dc:date>2011-07-07T14:14:48Z</dc:date>
    <item>
      <title>Cannot Open Shapefile</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/cannot-open-shapefile/m-p/139128#M3602</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a problem with opening shape file. I have a shape file in "C:\Shared\sample\sample.shp" (Of course the other files with extension dbf, prj, sbn, sbx, shp.xml and shx are in the same directory.) When I run the code below, I receive the exception called COMException was unhandled "Exception from HRESULT: 0x80040228". &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am running this code in Windows 7 Professional 64bit, ArcGIS 10 Engine and Visual Studio project target platform is x86.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you have any idea, about the problem, please help me.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks in advance.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Kerem Celik.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
Type factory_type = Type.GetTypeFromProgID("esriDataSourcesFile.ShapefileWorkspaceFactory");

IWorkspaceFactory workspace_factory = (IWorkspaceFactory)Activator.CreateInstance(factory_type);

IFeatureWorkspace workspace = (IFeatureWorkspace)workspace_factory.OpenFromFile(@"C:\Shared\sample\", 0);

IFeatureClass feature_class = workspace.OpenFeatureClass(System.IO.Path.GetFileName(sample);

ESRI.ArcGIS.Carto.IFeatureLayer feature_layer = new FeatureLayerClass();

feature_layer.FeatureClass = (IFeatureClass)feature_class;

default_map.AddLayer((ILayer)feature_layer);
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 Feb 2011 07:58:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/cannot-open-shapefile/m-p/139128#M3602</guid>
      <dc:creator>KeremCelik</dc:creator>
      <dc:date>2011-02-23T07:58:52Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Open Shapefile</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/cannot-open-shapefile/m-p/139129#M3603</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I really stuck on this problem. I have to solve it somehow. I need to load shape file programmatically, as explained in the thread above.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Please help me.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Kerem.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Feb 2011 07:52:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/cannot-open-shapefile/m-p/139129#M3603</guid>
      <dc:creator>KeremCelik</dc:creator>
      <dc:date>2011-02-28T07:52:51Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Open Shapefile</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/cannot-open-shapefile/m-p/139130#M3604</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Not sure if you ever got this working but since your code helped me get adding shapefiles...&amp;nbsp; I figured I would post how I did it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
// Variables
string fullpathToShapefile = "C:\Shared\sample\sample.shp"
string shp_path = Path.GetDirectoryName(fullpathToShapefile); // This will be "C:\Shared\sample"
string shp_name = Path.GetFileNameWithoutExtension(fullpathToShapefile); // this will be&amp;nbsp; "sample"

Type factory_type = Type.GetTypeFromProgID("esriDataSourcesFile.ShapefileWorkspaceFactory");
IWorkspaceFactory ShpWksFact = (IWorkspaceFactory)Activator.CreateInstance(factory_type);

IFeatureWorkspace FeatWks = (IFeatureWorkspace)ShpWksFact.OpenFromFile(shp_path, 0);
IFeatureClass FeatClass = FeatWks.OpenFeatureClass(shp_name);
IFeatureLayer FeatLayer = new FeatureLayerClass();

FeatLayer.FeatureClass = FeatClass;
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope it helps&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:42:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/cannot-open-shapefile/m-p/139130#M3604</guid>
      <dc:creator>EdEngle</dc:creator>
      <dc:date>2021-12-11T07:42:01Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Open Shapefile</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/cannot-open-shapefile/m-p/139131#M3605</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Which statement throws the exception?&amp;nbsp; What is the exact string value that is being evaluated with your expression System.IO.Path.GetFileName(sample)?&amp;nbsp; Does it include the .shp extension?&amp;nbsp; If so, try without the .shp extension.&amp;nbsp; The below code snippet states to specify the shapefile name without the extension.&amp;nbsp; Try both ways as a test and make sure you are not missing a close parenthesis:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/Get_FeatureClass_From_Shapefile_On_Disk_Snippet/00490000008m000000/"&gt;http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/Get_FeatureClass_From_Shapefile_On_Disk_Snippet/00490000008m000000/&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Feb 2011 23:01:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/cannot-open-shapefile/m-p/139131#M3605</guid>
      <dc:creator>EdgarBejarano</dc:creator>
      <dc:date>2011-02-28T23:01:01Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Open Shapefile</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/cannot-open-shapefile/m-p/139132#M3606</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Which statement throws the exception?&amp;nbsp; What is the exact string value that is being evaluated with your expression System.IO.Path.GetFileName(sample)?&amp;nbsp; Does it include the .shp extension?&amp;nbsp; If so, try without the .shp extension.&amp;nbsp; The below code snippet states to specify the shapefile name without the extension.&amp;nbsp; Try both ways as a test and make sure you are not missing a close parenthesis:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/Get_FeatureClass_From_Shapefile_On_Disk_Snippet/00490000008m000000/"&gt;http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/Get_FeatureClass_From_Shapefile_On_Disk_Snippet/00490000008m000000/&lt;/A&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The exception is thrown in the line IFeatureWorkspace workspace = (IFeatureWorkspace)workspace_factory.OpenFromFile(@"C:\Shared\sample\", 0);&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It says : COMException was unhandled "Exception from HRESULT: 0x80040228"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Kerem.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Mar 2011 13:22:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/cannot-open-shapefile/m-p/139132#M3606</guid>
      <dc:creator>KeremCelik</dc:creator>
      <dc:date>2011-03-01T13:22:25Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Open Shapefile</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/cannot-open-shapefile/m-p/139133#M3607</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Not sure if you ever got this working but since your code helped me get adding shapefiles...&amp;nbsp; I figured I would post how I did it.&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
// Variables
string fullpathToShapefile = "C:\Shared\sample\sample.shp"
string shp_path = Path.GetDirectoryName(fullpathToShapefile); // This will be "C:\Shared\sample"
string shp_name = Path.GetFileNameWithoutExtension(fullpathToShapefile); // this will be&amp;nbsp; "sample"

Type factory_type = Type.GetTypeFromProgID("esriDataSourcesFile.ShapefileWorkspaceFactory");
IWorkspaceFactory ShpWksFact = (IWorkspaceFactory)Activator.CreateInstance(factory_type);

IFeatureWorkspace FeatWks = (IFeatureWorkspace)ShpWksFact.OpenFromFile(shp_path, 0);
IFeatureClass FeatClass = FeatWks.OpenFeatureClass(shp_name);
IFeatureLayer FeatLayer = new FeatureLayerClass();

FeatLayer.FeatureClass = FeatClass;
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;Hope it helps&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for your help &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;kashmir772&lt;/SPAN&gt;&lt;SPAN&gt; but the code snippet you provided does not work for me.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;There is a problem with IFeatureWorkspace's OpenFromFile function. All I know just an error code (COMException was unhandled "Exception from HRESULT: 0x80040228").&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Kerem.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:42:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/cannot-open-shapefile/m-p/139133#M3607</guid>
      <dc:creator>KeremCelik</dc:creator>
      <dc:date>2021-12-11T07:42:04Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Open Shapefile</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/cannot-open-shapefile/m-p/139134#M3608</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Is this in a stand-alone application, e.g. a MapControl or are you compiling a DLL to register with ArcGIS Desktop?&amp;nbsp; If the former, are you initializing with a license?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;ESRI.ArcGIS.esriSystem.IAoInitialize&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Mar 2011 22:56:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/cannot-open-shapefile/m-p/139134#M3608</guid>
      <dc:creator>EdgarBejarano</dc:creator>
      <dc:date>2011-03-01T22:56:03Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Open Shapefile</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/cannot-open-shapefile/m-p/139135#M3609</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;By the way, I tested your exact code and it does not throw the exception at the reported statement, thus I wonder if you have initialized ArcObjects with a valid license (if a stand-alone application)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Mar 2011 22:59:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/cannot-open-shapefile/m-p/139135#M3609</guid>
      <dc:creator>EdgarBejarano</dc:creator>
      <dc:date>2011-03-01T22:59:06Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Open Shapefile</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/cannot-open-shapefile/m-p/139136#M3610</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi there,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hopefully if someone can explain how to open shape files in arcgis. Do I need to write code. Which code do I have to and where shall I write it exactly. Please I hope someone can help me.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks a million in advance.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Jul 2011 14:14:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/cannot-open-shapefile/m-p/139136#M3610</guid>
      <dc:creator>WilliamSmith4</dc:creator>
      <dc:date>2011-07-07T14:14:48Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot Open Shapefile</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/cannot-open-shapefile/m-p/139137#M3611</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Error 0x80040228 is usually related to the license not being initialized.&amp;nbsp; Are you sure the license is activated?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://forums.esri.com/Thread.asp?c=159&amp;amp;f=1707&amp;amp;t=200073"&gt;http://forums.esri.com/Thread.asp?c=159&amp;amp;f=1707&amp;amp;t=200073&lt;/A&gt;&lt;BR /&gt;&lt;A href="http://forums.esri.com/Thread.asp?c=2&amp;amp;f=1720&amp;amp;t=237013"&gt;http://forums.esri.com/Thread.asp?c=2&amp;amp;f=1720&amp;amp;t=237013&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Can you specify which version of ArcGIS you have (licensing has changed is 10)?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Can you specify the product installed?&amp;nbsp; Engine, desktop etc?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Can you specify the type of project, exe, add-in, dll customization?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Can you post the code that activates the license?&amp;nbsp; and the return values from the activation?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Can you specify which license you are using (engine, viewer, editor, arcinfo...)?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Jul 2011 15:50:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/cannot-open-shapefile/m-p/139137#M3611</guid>
      <dc:creator>AlexanderGray</dc:creator>
      <dc:date>2011-07-07T15:50:07Z</dc:date>
    </item>
  </channel>
</rss>

