I was trying to add a layer from my file geodatabase using Pro SDK. Keep getting "Failed to add data, unsupported data type". I can manually add it to Pro without any issues. Any ideas?
Here are my codes:
await QueuedTask.Run(()=>
{
Uri uri = new Uri(sPrjDB + "\\Map\\Map.gdb\\Pipe");
LayerFactory.Instance.CreateLayer(uri, MapView.Active.Map);
});
Your snippet looks correct, see here. The error message unfortunately is not very descriptive as to the cause. So I would look at the input parameters, especially the path: sPrjDB + "\\Map\\Map.gdb\\Pipe"
I would make sure that this path matches the path (and the feature class name) of the manually added layer. You can find the path by going to the content Dockpane, right-click on the feature layer, select properties, and then source.
Thank you. The path is correct.
Hi Fayu,
Here is a code snippet add a feature class from a file gdb. I got this from a previous answer posted by Wolf.
// Add this in your OnClick code-behind for the button
if (MapView.Active?.Map == null) return;
ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
// using the community sample dataset
using (Geodatabase geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(@"C:\Data\FeatureTest\FeatureTest.gdb"))))
{
using (FeatureClass addFeatureClass = geodatabase.OpenDataset<FeatureClass>("TestLines"))
{
LayerFactory.Instance.CreateFeatureLayer(addFeatureClass, MapView.Active.Map, 0, "New FC");
}
}
});
Thanks
Uma
This fixed my issue. Thank you, Uma!
But I found out LayerFactory.Instance.CreateFeatureLayer(new Uri(Path), MapView.Active.Map) will work on new created geodatabase. Not those created in ArcMap.