Select to view content in your preferred language

OpenFeatureClass throwing an Error: Exception from HRESULT: 0x80040351

2278
1
03-23-2011 08:15 AM
DaviKucharski
Deactivated User
Hello,

I am trying to run one of the examples on adding Dynamic Data. I have the following code:

Dim filePath As String = "C:\"
Dim fileName As String = "us_lakes.shp"

' Get a reference to the shapefile directory as an ArcObjects FeatureWorkspace
Dim workspaceFactory As ESRI.ArcGIS.Geodatabase.IWorkspaceFactory = CType(serverContext.CreateObject("esriDataSourcesFile.ShapefileWorkspaceFactory"), ESRI.ArcGIS.Geodatabase.IWorkspaceFactory)
Dim workspace As ESRI.ArcGIS.Geodatabase.IWorkspace = workspaceFactory.OpenFromFile(filePath, 0) Dim featureWorkspace As ESRI.ArcGIS.Geodatabase.IFeatureWorkspace = CType(workspace, ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)

' Get a reference to the shapefile as a GeoFeatureLayer
Dim aoFeatureLayer As ESRI.ArcGIS.Carto.IFeatureLayer = CType(serverContext.CreateObject("esriCarto.FeatureLayer"), ESRI.ArcGIS.Carto.IFeatureLayer)
  aoFeatureLayer.FeatureClass = featureWorkspace.OpenFeatureClass(fileName)

I am getting an error on the line in red. I know the file exists on the C:\ and it is one of the files supplied by ESRI when installing. I don't know what else I need to do. Please let me know.

Lastly, if my filepath is anything other that C:\, like C:\temp\data, the line in blue fails. I don't know why that is either. Please help.
0 Kudos
1 Reply
SebastianKrings
Frequent Contributor
you my have a problem using escape sequences
"\" is such an escape sequence and will not be interpretet as a string or char
I dont know how this is soluted in VBA but in c# you have to use "\\" (the first "\" says to use the second one als char)
or you can add an @ before your string

try this:
Dim filePath As String = "C:\\"
Dim filePath As String = @"C:\"
Dim filePath As String = "C:\\temp\\data"
Dim filePath As String = @"C:\temp\data"
0 Kudos