ArcGIS Runtime SDK for WPF - Library Reference
DownloadStringCompleted Event
See Also  Example
ESRI.ArcGIS.Client Namespace > ArcGISWebClient Class : DownloadStringCompleted Event

Occurs when an asynchronous download string operation completes.

Syntax

Visual Basic (Declaration) 
Public Event DownloadStringCompleted As EventHandler(Of ArcGISWebClient.DownloadStringCompletedEventArgs)

Remarks

Use the ArcGISWebClient.DownloadStringAsync Method / ArcGISWebClient.DownloadStringCompleted Event to process (read/write) text such as: JSON, XAML, XML, and HTML.

Use the ArcGISWebClient.OpenReadAsync Method / ArcGISWebClient.OpenReadCompleted Event to process (read/write) binary streams of data such as: images, files (.doc, .pdf, .exe), music, movies, etc.

Event Data

The event handler receives an argument of type ArcGISWebClient.DownloadStringCompletedEventArgs containing data related to this event. The following ArcGISWebClient.DownloadStringCompletedEventArgs properties provide information specific to this event.

PropertyDescription
Cancelled (Inherited from System.ComponentModel.AsyncCompletedEventArgs) 
Error (Inherited from System.ComponentModel.AsyncCompletedEventArgs) 
Result Gets the data that is downloaded by ArcGISWebClient.DownloadStringAsync.
UserState (Inherited from System.ComponentModel.AsyncCompletedEventArgs) 

Example

How to use:

The XAML code in this example is used in conjunction with the code-behind (C# or VB.NET) to demonstrate the functionality.

The following screen shot corresponds to the code example in this page.

Using the ArcGISWebClient.DownloadStringAsync Method to obtain JSON string information from ArcGIS Server.

XAMLCopy Code
<Grid x:Name="LayoutRoot" Background="White">
  
  <!-- Url for the ArcGISWebClient operation. -->
  <TextBox Height="44" HorizontalAlignment="Left" Margin="4,181,0,0" Name="TextBox_Url" VerticalAlignment="Top" Width="575" 
  Text="http://services.arcgisonline.com/ArcGIS/rest/services/Demographics/USA_Median_Age/MapServer/4/query?where=1%3D1&amp;returnCountOnly=true&amp;f=json"
  TextWrapping="Wrap"/>
  
  <!-- Button to perform the work. -->
  <Button Content="DownloadStringAsync" Height="24" Width="201" HorizontalAlignment="Left" Margin="4,232,0,0" 
          Name="Button_DownloadStringAsync" VerticalAlignment="Top" Click="Button_DownloadStringAsync_Click" />
  
  <!-- CheckBox option to display the ArcGISWebClient Response JSON in a MessageBox or TextBox.-->
  <CheckBox Content="Display Results in a MessageBox" Height="16" HorizontalAlignment="Left" Margin="211,235,0,0" 
            Name="CheckBox1" VerticalAlignment="Top" />
  
  <!-- Display the Response for the ArcGISWebClient operation. -->
  <TextBox Height="95" HorizontalAlignment="Left" Margin="4,262,0,0" Name="TextBox_Response" 
           VerticalAlignment="Top" Width="575" VerticalScrollBarVisibility="Auto" 
           HorizontalScrollBarVisibility="Auto" />
  
  <!-- Provide the instructions on how to use the sample code. -->
  <TextBlock Height="94" HorizontalAlignment="Left" Name="TextBlock1" VerticalAlignment="Top" Width="625" 
  TextWrapping="Wrap" Text="Click the 'DownloadStringAsync' Button to start an ArcGISWebClient operation. Check 
  'on' the CheckBox if you want to see the JSON results in a MessageBox, otherwise the result will
  display in the TextBox. The JSON result returned is a count of the number of features in a FeatureLayer." />
  
</Grid>
C#Copy Code
private void Button_DownloadStringAsync_Click(object sender, System.Windows.RoutedEventArgs e)
{
  // Clear out any existing information in the TextBox.
  TextBox_Response.Text = "";
  
  // Create a new ArcGISWebClient object.
  ESRI.ArcGIS.Client.ArcGISWebClient myArcGISWebClient = new ESRI.ArcGIS.Client.ArcGISWebClient();
  
  // Wire up an Event Handler for the ArcGISWebClient.DownloadStringCompleted Event.
  myArcGISWebClient.DownloadStringCompleted += arcgisWebClient_DownloadStringCompleted;
  
  // Get the Url for the ArcGISWebClient request.
  string myUrl = TextBox_Url.Text;
  
  // Get the userState (aka. user token) to determine how to display the results of the ArcGISWebClient operation.
  bool myUserToken = (bool)CheckBox1.IsChecked;
  
  // Invoke the ArcGISWebClient.DownloadStringAsync Method passing in the Url, nothing for the parameter collection, and a user token.
  // This ArcGISWebClient operation is very small, use the HttpMethods.Get enumeration. You could leave
  // this parameter unspecified, which will by default use the HttpMethods.Auto enumeration. HttpMethods.Auto lets
  // the application choose the best communication method to use based upon the request being made and the 
  // capabilities of the client host container.
  myArcGISWebClient.DownloadStringAsync(new Uri(myUrl), null, ESRI.ArcGIS.Client.ArcGISWebClient.HttpMethods.Get, myUserToken);
}
            
private void arcgisWebClient_DownloadStringCompleted(object sender, ESRI.ArcGIS.Client.ArcGISWebClient.DownloadStringCompletedEventArgs e)
{
  // Get the userState (aka. user token) from the ArcGISWebClient operation.
  bool myUserToken = (bool)e.UserState;
  
  // Get the JSON string result from the ArcGISWebClient operation.
  string theResult = e.Result;
  
  if (myUserToken == true)
  {
    // Display the JSON string response in a MessageBox.
    MessageBox.Show(theResult);
  }
  else
  {
    // Display the JSON string response in the TextBox.
  TextBox_Response.Text = theResult;
  }
}
VB.NETCopy Code
Private Sub Button_DownloadStringAsync_Click(sender As System.Object, e As System.Windows.RoutedEventArgs)
  
  ' Clear out any existing information in the TextBox.
  TextBox_Response.Text = ""
  
  ' Create a new ArcGISWebClient object.
  Dim myArcGISWebClient As ESRI.ArcGIS.Client.ArcGISWebClient = New ESRI.ArcGIS.Client.ArcGISWebClient
  
  ' Wire up an Event Handler for the ArcGISWebClient.DownloadStringCompleted Event.
  AddHandler myArcGISWebClient.DownloadStringCompleted, AddressOf arcgisWebClient_DownloadStringCompleted
  
  ' Get the Url for the ArcGISWebClient request.
  Dim myUrl As String = TextBox_Url.Text
  
  ' Get the userState (aka. user token) to determine how to display the results of the ArcGISWebClient operation.
  Dim myUserToken As Boolean = CheckBox1.IsChecked
  
  ' Invoke the ArcGISWebClient.DownloadStringAsync Method passing in the Url, nothing for the parameter collection, and a user token.
  ' This ArcGISWebClient operation is very small, use the HttpMethods.Get enumeration. You could leave
  ' this parameter unspecified, which will by default use the HttpMethods.Auto enumeration. HttpMethods.Auto lets
  ' the application choose the best communication method to use based upon the request being made and the 
  ' capabilities of the client host container.
  myArcGISWebClient.DownloadStringAsync(New Uri(myUrl), Nothing, ESRI.ArcGIS.Client.ArcGISWebClient.HttpMethods.Get, myUserToken)
  
End Sub
            
Private Sub arcgisWebClient_DownloadStringCompleted(sender As Object, e As ESRI.ArcGIS.Client.ArcGISWebClient.DownloadStringCompletedEventArgs)
  
  ' Get the userState (aka. user token) from the ArcGISWebClient operation.
  Dim myUserToken As Boolean = e.UserState
  
  ' Get the JSON string result from the ArcGISWebClient operation.
  Dim theResult As String = e.Result
  
  If myUserToken = True Then
    
    ' Display the JSON string response in a MessageBox.
    MessageBox.Show(theResult)
    
  Else
     
    ' Display the JSON string response in the TextBox.
    TextBox_Response.Text = theResult
    
  End If
  
End Sub

Requirements

Target Platforms: Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family, Windows 7, Windows 8

See Also

© ESRI, Inc. All Rights Reserved.