I have found that there exist some python script to export Survey123 data to your computer. Is there any similar code using the C# language with the ArcGIS Runtime SDK version 100.2.1?
I am trying to follow this link: Access the ArcGIS platform—ArcGIS Runtime SDK for .NET (WPF) | ArcGIS for Developers
But my application crash at the first line ( ArcGISPortal portal = <SPAN class="">await</SPAN> ArcGISPortal.CreateAsync(); )
Error code is the following:
"Une erreur s'est produite lors de l'envoi de la demande." System.Exception {System.Net.Http.HttpRequestException}
Any idea why?
EDIT: I found additionnal information about the error:
Proxy Authentication Required ( The ISA Server requires authorization to fulfill the request. Access to the Web Proxy filter is denied. )
EDIT: All problems solved. Here is the complete c# code to extract and delete the data (make sure you install and reference the arcgis Runtime .Net sdk and newtonSoft.JSON):
<SPAN class="keyword token">using</SPAN> System<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">using</SPAN> System<SPAN class="punctuation token">.</SPAN>Collections<SPAN class="punctuation token">.</SPAN>Generic<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">using</SPAN> System<SPAN class="punctuation token">.</SPAN>ComponentModel<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">using</SPAN> System<SPAN class="punctuation token">.</SPAN>Data<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">using</SPAN> System<SPAN class="punctuation token">.</SPAN>Drawing<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">using</SPAN> System<SPAN class="punctuation token">.</SPAN>Linq<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">using</SPAN> System<SPAN class="punctuation token">.</SPAN>Text<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">using</SPAN> System<SPAN class="punctuation token">.</SPAN>Threading<SPAN class="punctuation token">.</SPAN>Tasks<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">using</SPAN> System<SPAN class="punctuation token">.</SPAN>Windows<SPAN class="punctuation token">.</SPAN>Forms<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">using</SPAN> Esri<SPAN class="punctuation token">.</SPAN>ArcGISRuntime<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">using</SPAN> Esri<SPAN class="punctuation token">.</SPAN>ArcGISRuntime<SPAN class="punctuation token">.</SPAN>Security<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">using</SPAN> Esri<SPAN class="punctuation token">.</SPAN>ArcGISRuntime<SPAN class="punctuation token">.</SPAN>Portal<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">using</SPAN> Esri<SPAN class="punctuation token">.</SPAN>ArcGISRuntime<SPAN class="punctuation token">.</SPAN>Data<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">using</SPAN> System<SPAN class="punctuation token">.</SPAN>Net<SPAN class="punctuation token">.</SPAN>Http<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">using</SPAN> System<SPAN class="punctuation token">.</SPAN>Threading<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">using</SPAN> System<SPAN class="punctuation token">.</SPAN>IO<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">using</SPAN> System<SPAN class="punctuation token">.</SPAN>Net<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">using</SPAN> System<SPAN class="punctuation token">.</SPAN>Collections<SPAN class="punctuation token">.</SPAN>Specialized<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">using</SPAN> Newtonsoft<SPAN class="punctuation token">.</SPAN>Json<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">namespace</SPAN> xFormAGO
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">public</SPAN> <SPAN class="keyword token">partial</SPAN> <SPAN class="keyword token">class</SPAN> <SPAN class="token class-name">Form1</SPAN> <SPAN class="punctuation token">:</SPAN> Form
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">string</SPAN> nomUtilisateur <SPAN class="operator token">=</SPAN> <SPAN class="string token">"yourusername"</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">string</SPAN> motPass <SPAN class="operator token">=</SPAN> <SPAN class="string token">"yourPassword"</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">//Your service URL will be different but similar</SPAN>
<SPAN class="keyword token">string</SPAN> ServiceUrl <SPAN class="operator token">=</SPAN> <SPAN class="string token"><SPAN>@"</SPAN><A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=https%3A%2F%2Fservices1.arcgis.com%2Fxas33e1csd2dYTMBwrt4%2FArcGIS%2Frest%2Fservices%2Fservice_832yf5aaa3a341fgucc03f946c89643%2FFeatureServer%2F0%2F" target="_blank">https://services1.arcgis.com/xas33e1csd2dYTMBwrt4/ArcGIS/rest/services/service_832yf5aaa3a341fgucc03f946c89643/FeatureServer/0/</A><SPAN>"</SPAN></SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//Layer 0</SPAN>
<SPAN class="keyword token">string</SPAN> dossier <SPAN class="operator token">=</SPAN> <SPAN class="string token">@"C:\test\";
string fichier = "</SPAN>data<SPAN class="punctuation token">.</SPAN>txt"<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">public</SPAN> <SPAN class="token function">Form1</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="token function">InitializeComponent</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
WebRequest<SPAN class="punctuation token">.</SPAN>DefaultWebProxy<SPAN class="punctuation token">.</SPAN>Credentials <SPAN class="operator token">=</SPAN> CredentialCache<SPAN class="punctuation token">.</SPAN>DefaultNetworkCredentials<SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="comment token">//This button extract the data</SPAN>
<SPAN class="keyword token">private</SPAN> <SPAN class="keyword token">async</SPAN> <SPAN class="keyword token">void</SPAN> <SPAN class="token function">cmdExtraction_Click</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">object</SPAN> sender<SPAN class="punctuation token">,</SPAN> EventArgs e<SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">try</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="comment token">//Create ArcGIS Token</SPAN>
<SPAN class="keyword token">var</SPAN> cred <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">await</SPAN> Esri<SPAN class="punctuation token">.</SPAN>ArcGISRuntime<SPAN class="punctuation token">.</SPAN>Security<SPAN class="punctuation token">.</SPAN>AuthenticationManager<SPAN class="punctuation token">.</SPAN>Current<SPAN class="punctuation token">.</SPAN><SPAN class="token function">GenerateCredentialAsync</SPAN><SPAN class="punctuation token">(</SPAN>
<SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Uri</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token"><SPAN>"</SPAN><A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=https%3A%2F%2Fwww.arcgis.com%2Fsharing%2Frest" target="_blank">https://www.arcgis.com/sharing/rest</A><SPAN>"</SPAN></SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN>
nomUtilisateur<SPAN class="punctuation token">,</SPAN>
motPass<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> ArcGISTokenCredential<SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">//Build POST request</SPAN>
<SPAN class="keyword token">string</SPAN> reponseStr<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">using</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">var</SPAN> wb <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">WebClient</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="comment token">//Request parameter. This one just download all data and Fields</SPAN>
<SPAN class="keyword token">var</SPAN> requete <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">NameValueCollection</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
requete<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"where"</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> <SPAN class="string token">"1=1"</SPAN><SPAN class="punctuation token">;</SPAN>
requete<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"f"</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> <SPAN class="string token">"json"</SPAN><SPAN class="punctuation token">;</SPAN>
requete<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"outFields"</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> <SPAN class="string token">"*"</SPAN><SPAN class="punctuation token">;</SPAN>
requete<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"token"</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> cred<SPAN class="punctuation token">.</SPAN>Token<SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//Important! Must be present</SPAN>
<SPAN class="comment token">//Send request and wait for answer</SPAN>
<SPAN class="keyword token">var</SPAN> response <SPAN class="operator token">=</SPAN> wb<SPAN class="punctuation token">.</SPAN><SPAN class="token function">UploadValues</SPAN><SPAN class="punctuation token">(</SPAN>ServiceUrl <SPAN class="operator token">+</SPAN> <SPAN class="string token">"query"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"POST"</SPAN><SPAN class="punctuation token">,</SPAN> requete<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
reponseStr <SPAN class="operator token">=</SPAN> Encoding<SPAN class="punctuation token">.</SPAN>UTF8<SPAN class="punctuation token">.</SPAN><SPAN class="token function">GetString</SPAN><SPAN class="punctuation token">(</SPAN>response<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//Translate the answer to a JSON STRING</SPAN>
<SPAN class="punctuation token">}</SPAN>
File<SPAN class="punctuation token">.</SPAN><SPAN class="token function">WriteAllText</SPAN><SPAN class="punctuation token">(</SPAN>dossier <SPAN class="operator token">+</SPAN> fichier<SPAN class="punctuation token">,</SPAN> reponseStr<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//Export the JSON string into a text file</SPAN>
Rootobject dataResults <SPAN class="operator token">=</SPAN> JsonConvert<SPAN class="punctuation token">.</SPAN>DeserializeObject<SPAN class="operator token"><</SPAN>Rootobject<SPAN class="operator token">></SPAN><SPAN class="punctuation token">(</SPAN>reponseStr<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//Build the object containing the data. This line will crash for you here. Use google to understand how to convert a JSON string to a C# object. Or see the notes at the end of this code.</SPAN>
<SPAN class="comment token">//Use this object to manipulate your data as you wish</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">catch</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="token class-name">Exception</SPAN> exp<SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">throw</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Exception</SPAN><SPAN class="punctuation token">(</SPAN>exp<SPAN class="punctuation token">.</SPAN>Message<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="comment token">//This button delete the data</SPAN>
<SPAN class="keyword token">private</SPAN> <SPAN class="keyword token">async</SPAN> <SPAN class="keyword token">void</SPAN> <SPAN class="token function">cmdSupprimer_Click</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">object</SPAN> sender<SPAN class="punctuation token">,</SPAN> EventArgs e<SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="comment token">//Create ArcGIS Token</SPAN>
<SPAN class="keyword token">var</SPAN> cred <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">await</SPAN> Esri<SPAN class="punctuation token">.</SPAN>ArcGISRuntime<SPAN class="punctuation token">.</SPAN>Security<SPAN class="punctuation token">.</SPAN>AuthenticationManager<SPAN class="punctuation token">.</SPAN>Current<SPAN class="punctuation token">.</SPAN><SPAN class="token function">GenerateCredentialAsync</SPAN><SPAN class="punctuation token">(</SPAN>
<SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Uri</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token"><SPAN>"</SPAN><A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=https%3A%2F%2Fwww.arcgis.com%2Fsharing%2Frest" target="_blank">https://www.arcgis.com/sharing/rest</A><SPAN>"</SPAN></SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN>
nomUtilisateur<SPAN class="punctuation token">,</SPAN>
motPass<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> ArcGISTokenCredential<SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">//POST request to delete data</SPAN>
<SPAN class="keyword token">using</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">var</SPAN> wb <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">WebClient</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="comment token">//This request deletes everything in the layer 0</SPAN>
<SPAN class="keyword token">var</SPAN> data <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">NameValueCollection</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
data<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"where"</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> <SPAN class="string token">"1=1"</SPAN><SPAN class="punctuation token">;</SPAN>
data<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"f"</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> <SPAN class="string token">"json"</SPAN><SPAN class="punctuation token">;</SPAN>
data<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"token"</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> cred<SPAN class="punctuation token">.</SPAN>Token<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> response2 <SPAN class="operator token">=</SPAN> wb<SPAN class="punctuation token">.</SPAN><SPAN class="token function">UploadValues</SPAN><SPAN class="punctuation token">(</SPAN>ServiceUrl <SPAN class="operator token">+</SPAN> <SPAN class="string token">"deleteFeatures"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"POST"</SPAN><SPAN class="punctuation token">,</SPAN> data<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">string</SPAN> responseInString <SPAN class="operator token">=</SPAN> Encoding<SPAN class="punctuation token">.</SPAN>UTF8<SPAN class="punctuation token">.</SPAN><SPAN class="token function">GetString</SPAN><SPAN class="punctuation token">(</SPAN>response2<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">//Check the value of responseInString to see if deletion was successful</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="comment token">//</SPAN>
<SPAN class="comment token">//Here you will past the content of "data.txt" that you received earlier!!!</SPAN>
<SPAN class="comment token">//Very important</SPAN>
<SPAN class="comment token">//</SPAN>
<SPAN class="comment token">//Using visual studio, you will do a special paste as follow:</SPAN>
<SPAN class="comment token">//-Open the data.txt file</SPAN>
<SPAN class="comment token">//-Copy all content</SPAN>
<SPAN class="comment token">//-Return back to visual studio and do a special "Paste as JSON format (Edition / special paste / paste JSON code as class)</SPAN>
<SPAN class="comment token">//You will then be able to use a similar line of code: Rootobject dataResults = JsonConvert.DeserializeObject<Rootobject>(reponseStr);</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>