Select to view content in your preferred language

IWorkspace.PathName returns empty string

857
5
10-12-2011 08:28 AM
JamesLanyon
Emerging Contributor
I have a frustrating unpredictable situation where for some reason (which I have yet discovered the reason) when I call IWorkspace.PathName I get an empty string. I am solely dealing with personal GDB feature classes - no remote database workspaces involved. I initially thought it was down to the fact that I had a large number of layers loaded in my TOC all located in my PGDB, so removed all of the unnecessary layers before calling the code. This appears to sort the problem for 99% of the time, but hasn't solved it completely. I'm running 9.3 on XP (32 and 64-bit) and get the empty string returned on both platforms. I've noticed users finding this occurring with SDE databases but not with PGDBs - has anyone experienced this?

Thanks
James
0 Kudos
5 Replies
JamesCrandall
MVP Alum
I have a frustrating unpredictable situation where for some reason (which I have yet discovered the reason) when I call IWorkspace.PathName I get an empty string. I am solely dealing with personal GDB feature classes - no remote database workspaces involved. I initially thought it was down to the fact that I had a large number of layers loaded in my TOC all located in my PGDB, so removed all of the unnecessary layers before calling the code. This appears to sort the problem for 99% of the time, but hasn't solved it completely. I'm running 9.3 on XP (32 and 64-bit) and get the empty string returned on both platforms. I've noticed users finding this occurring with SDE databases but not with PGDBs - has anyone experienced this?

Thanks
James


James,

How are you going thru the list of layers in the TOC?  This is just a hunch, but are you accounting for the zero-based index count? 

For example,

For i = 0 To pMap.LayerCount - 1
  'get the pathName of the pMap.Layer(i)
Next


this would start at the first layer and end at the last one.  If you didn't specify -1 on the layerCount, it could potentially sequence to a nothing for the layer and return an null/empty string or throwing an ArgumnetExeption -- and depending upon how you are handling the error it might be the cause of the empty null being returned.

Post up some of the code you suspect is giving the problems.
0 Kudos
JamesCrandall
MVP Alum
Also, I just found this in the documentation:

"...If an SDE workspace was created from a PropertySet, PathName will be empty"

See here: http://edndoc.esri.com/arcobjects/9.0/componenthelp/esriGeodatabase/IWorkspace_PathName.htm
0 Kudos
JamesLanyon
Emerging Contributor
Hi James,

Thanks for replying to my post - the code that returns an empty string doesn't involve a loop through the layers in the TOC, I'm using this property to get the full file path to my featureclass by simply casting the featureclass as an IDataset and then getting the Workspace.PathName property from this, ie.

Dim pDataset as IDataset
Set pDataset = pFeatureClass
Dim pWorkspace as IWorkspace
Set pWorkspace = pDataset.Workspace 'This does not get set to Nothing
Dim sPath as String
sPath = pWorkspace.PathName 'This returns an empty string even though pWorkspace is set

The feature class is a personal geodatabase featureclass, I'm not dealing with SDE featureclasses so unfortunately your second post doesn't apply, but thanks for looking into this.

James
0 Kudos
JamesCrandall
MVP Alum

The feature class is a personal geodatabase featureclass, I'm not dealing with SDE featureclasses so unfortunately your second post doesn't apply, but thanks for looking into this.


But from your original post you say that this occurs with SDE FeatureClasses...

[INDENT]"...I've noticed users finding this occurring with SDE databases but not with PGDBs - has anyone experienced this?"[/INDENT]

I wonder if the issue is that because you have a large number of layers in the TOC that something isn't slipping by you that you think is something else (like an SDE FC or something and is the one that is causing problems).  In which case you might want to check/verify the type prior to checking it's path.  The help has an example:

Public Function GetPathForALayer(ByVal layer As ESRI.ArcGIS.Carto.ILayer) As System.String

If layer Is Nothing OrElse Not (TypeOf layer Is ESRI.ArcGIS.Geodatabase.IDataset) Then
  Return Nothing
End If

Dim dataset As ESRI.ArcGIS.Geodatabase.IDataset = CType(layer, ESRI.ArcGIS.Geodatabase.IDataset) ' Explicit Cast

Return (dataset.Workspace.PathName & "\" & dataset.Name)

End Function


http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/Get_Path_for_a_Layer_Sni...
0 Kudos
JamesLanyon
Emerging Contributor
Sorry for the confusion - I mentioned other users (ie. users in other threads, not users of my code) had experienced the same issue with SDE database feature classes, but I'm only using PGDB feature classes and tables. However, you may be on to something regarding the explicit cast of the IDataset to a ESRI.ArcGIS.Geodatabase.IDataset. I'll give this a try.

Thanks
James
0 Kudos