AnsweredAssumed Answered

How do i delete features using REST in my C# application?

Question asked by 25394 on Sep 27, 2017
Latest reply on Sep 29, 2017 by 25394

Hi, I am having problems deleting all features within my feature layer using the following code. I'm guessing my mistake is in the reqstring . I am having a heck of a time trying to find examples of URL's that will delete all my features. Any suggestions?

 

        static Boolean DeleteAllFeaturesFromFeatureService()
        {
            try
            {
               
                string reqString = "https://services1.arcgis.com/0PfllXX1nvjR0pWI/arcgis/rest/services/SHAPEFILE/FeatureServer/0/deleteFeatures?site_id=1";
                HttpWebRequest req = WebRequest.Create(new Uri(reqString)) as HttpWebRequest;
                req.Method = "POST";
                req.ContentType = "application/json";
                // Encode the parameters as form data:
                byte[] formData = UTF8Encoding.UTF8.GetBytes(reqString);
                //req.contentLength = formData.Length;
                // Send the request:
                using (Stream post = req.GetRequestStream())
                {
                    post.Write(formData, 0, formData.Length);
                }
                // Pick up the response:
                string result = null;
                using (HttpWebResponse resp = req.GetResponse() as HttpWebResponse)
                {
                    StreamReader reader =
                    new StreamReader(resp.GetResponseStream());
                    result = reader.ReadToEnd();
                    Console.WriteLine(result.ToString());
                }
                return true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return false;
            }
        }
    }

Outcomes