Delete Field

695
5
06-01-2022 03:04 AM
DavidMrázek
Occasional Contributor II

Hi,

I'm trying to get the columns out, but it doesn't do anything at all, I tried it gradually, I tried them all at once but without any success. Can anyone advise me?

FeatureLayer flRamyPresahu = mapView.Map.FindLayers(ramyPresahu).FirstOrDefault() as FeatureLayer;
 FeatureClass fcRamyPresahu = flRamyPresahu.GetTable() as FeatureClass;
 var minX = "ExtentMinX";
              var minY = "ExtentMinY";
              var maxX = "ExtentMaxX";
              var maxY = "ExtentMaxY";
object[] sloupce = {maxX,maxY,minX,minY};
              object[] seznamSloupcu = { fcRamyPresahu, sloupce };
              await StartATask("management.DeleteField", seznamSloupcu);
0 Kudos
5 Replies
KenBuja
MVP Esteemed Contributor

If your FeatureClass is in a geodatabase (file, mobile, enterprise, or memory), you can use this snippet to remove a field

https://github.com/Esri/arcgis-pro-sdk/wiki/ProSnippets-Geodatabase#removing-fields-from-a-table

Otherwise, you can use this code to use the GeoProcessing tool to remove a field.

var args = Geoprocessing.MakeValueArray(fcRamyPresahu, sloupce);
IGPResult result = await Geoprocessing.ExecuteToolAsync("management.DeleteField", args, null, null, null, GPExecuteToolFlags.None); //the last parameter does not add the result to the map

Read this page on more information about using GeoProcessing tools

0 Kudos
DavidMrázek
Occasional Contributor II

It has m processed in its

StartATask

 But thank you for your time.

0 Kudos
KenBuja
MVP Esteemed Contributor

What does your StartATask function look like?

0 Kudos
DavidMrázek
Occasional Contributor II
public static async Task<bool> StartATask(string funcArc, object[] parame)
        {
            var parameters = Geoprocessing.MakeValueArray(parame);
            await Geoprocessing.ExecuteToolAsync(funcArc, parameters);
            return true;
        }
0 Kudos
KenBuja
MVP Esteemed Contributor

Instead of just returning true, why not get a report on why it failed?

public static async Task<bool> StartATask(string funcArc, object[] parame)
{
  var parameters = Geoprocessing.MakeValueArray(parame);
  var result = await Geoprocessing.ExecuteToolAsync(funcArc, parameters);
  if (result.IsFailed)
  {
    Geoprocessing.ShowMessageBox(result.Messages, "Content Header", GPMessageBoxStyle.Error);
  }
  return !result.IsFailed;
}