title: How to use String in WebClient.DownloadStringAsync URL
body: <p>I currently have this for my <code>WebClient</code> URL:</p>
  <pre class="lang-cs prettyprint-override"><code>WebClient Detail = new WebClient();
  Detail.DownloadStringCompleted += new
      DownloadStringCompletedEventHandler(Detail_DownloadStringCompleted);
  Detail.DownloadStringAsync(new Uri(&quot;http://api.trademe.co.nz/v1/Listings/&quot; +
      ListingID.Text + &quot;.xml&quot;));
  </code></pre>
  <p>What I want to do is use this string:</p>
  <pre class="lang-cs prettyprint-override"><code>void ListBoxSelectionChanged(object sender, SelectionChangedEventArgs args)
  {
      var lbi = ((sender as ListBox).SelectedItem as TradeItem);
      if(lbi != null)
      {
          string id = lbi.ListingId.ToString();
      }
  }
  </code></pre>
  <p>As part of that <code>WebClient</code> URL.</p>
  <p>Example:</p>
  <pre class="lang-cs prettyprint-override"><code>WebClient Detail = new WebClient();
  Detail.DownloadStringCompleted += new
      DownloadStringCompletedEventHandler(Detail_DownloadStringCompleted);
  Detail.DownloadStringAsync(new Uri(&quot;http://api.trademe.co.nz/v1/Listings/&quot; + id +
      &quot;.xml&quot;));
  </code></pre>
  <p>Is there anyway to use this string in URL as show above?</p>
  <p>Complete code:</p>
  <pre class="lang-cs prettyprint-override"><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Net;
  using System.Windows;
  using System.Windows.Controls;
  using System.Windows.Documents;
  using System.Windows.Input;
  using System.Windows.Media;
  using System.Windows.Media.Animation;
  using System.Windows.Shapes;
  using Microsoft.Phone.Controls;
  using System.Xml.Linq;
  
  namespace TradeMe_Panorama
  {
      public partial class MainPage : PhoneApplicationPage
      {
          // Constructor.
          public MainPage()
          {
              InitializeComponent();
              // Set the data context of the listbox control to the sample data.
              DataContext = App.ViewModel;
              this.Loaded += new RoutedEventHandler(MainPage_Loaded);
          }
  
          // Load data for the ViewModel items.
          private void MainPage_Loaded(object sender, RoutedEventArgs e)
          {
              if (!App.ViewModel.IsDataLoaded)
              {
                  App.ViewModel.LoadData();
              }
          }
  
          private void button1_Click(object sender, RoutedEventArgs e)
          {
              WebClient Trademe = new WebClient();
              Trademe.DownloadStringCompleted += new   
              DownloadStringCompletedEventHandler(Trademe_DownloadStringCompleted);
              Trademe.DownloadStringAsync(new
              Uri(&quot;http://api.trademe.co.nz/v1/Search/General.xml?search_string=&quot; +
              TradeSearch.Text));
              progressBar1.IsIndeterminate = true;
              progressBar1.Visibility = Visibility.Visible;
          }
  
          // Display listing for used general products:
          void Trademe_DownloadStringCompleted(object sender,
              DownloadStringCompletedEventArgs e)
          {
              if (e.Error != null)
                  return;
              var r = XDocument.Parse(e.Result);
              // Declare the namespace.
              XNamespace ns = &quot;http://api.trademe.co.nz/v1&quot;;
              TradeSearch1.ItemsSource = from TM in r.Root.Descendants(ns +
                  &quot;Listing&quot;).Take(20)
              select new TradeItem
              {
                  ImageSource = TM.Element(ns + &quot;PictureHref&quot;).Value,
                  Title = TM.Element(ns + &quot;Title&quot;).Value,
                  Region = TM.Element(ns + &quot;Region&quot;).Value,
                  PriceDisplay = TM.Element(ns + &quot;PriceDisplay&quot;).Value,
                  ListingId = TM.Element(ns + &quot;ListingId&quot;).Value,
              };
              progressBar1.IsIndeterminate = false;
              progressBar1.Visibility = Visibility.Collapsed;
          }
  
          // Display listing for used Cars.
          private void button2_Click(object sender, RoutedEventArgs e)
          {
              WebClient Motor = new WebClient();
              Motor.DownloadStringCompleted += new
              DownloadStringCompletedEventHandler(Motor_DownloadStringCompleted);
              Motor.DownloadStringAsync(new
              Uri(&quot;http://api.trademe.co.nz/v1/Search/Motors/Used.xml?search_string=&quot; +
              MotorSearch.Text));
              progressBar1.IsIndeterminate = true;
              progressBar1.Visibility = Visibility.Visible;
          }        
  
          void Motor_DownloadStringCompleted(object sender,
              DownloadStringCompletedEventArgs e)
          {
              if (e.Error != null)
                  return;
              var r = XDocument.Parse(e.Result);
              // Declare the namespace.
              XNamespace ns = &quot;http://api.trademe.co.nz/v1&quot;;
              MotorsListings.ItemsSource = from M in r.Root.Descendants(ns +
                  &quot;Car&quot;).Take(20)
              select new TradeItem
              {
                  ImageSource = M.Element(ns + &quot;PictureHref&quot;).Value,
                  Title = M.Element(ns + &quot;Title&quot;).Value,
                  Region = M.Element(ns + &quot;Region&quot;).Value,
                  PriceDisplay = M.Element(ns + &quot;PriceDisplay&quot;).Value,
                  ListingId = M.Element(ns + &quot;ListingId&quot;).Value,
              };
              progressBar1.IsIndeterminate = false;
              progressBar1.Visibility = Visibility.Collapsed;
          }
  
          //Display specific details of listings:
          private void button4_Click(object sender, RoutedEventArgs e)
          {
              WebClient Detail = new WebClient();
              Detail.DownloadStringCompleted += new
              DownloadStringCompletedEventHandler(Detail_DownloadStringCompleted);
              Detail.DownloadStringAsync(new
              Uri(&quot;http://api.trademe.co.nz/v1/Listings/&quot; + ListingID.Text +
              &quot;.xml&quot;));
              progressBar1.IsIndeterminate = true;
              progressBar1.Visibility = Visibility.Visible;
          }
          
          void Detail_DownloadStringCompleted(object sender,
              DownloadStringCompletedEventArgs e)
          {
              if (e.Error != null)
                  return;
              var r = XDocument.Parse(e.Result);
              // Declare the namespace.
              XNamespace ns = &quot;http://api.trademe.co.nz/v1&quot;;
              ListingDetails.ItemsSource = from D in r.Descendants(ns +
              &quot;ListedItemDetail&quot;).Take(20)
              select new TradeItem
              {
                  ImageSource = D.Element(ns + &quot;Photos&quot;).Element(ns +
                  &quot;Photo&quot;).Element(ns + &quot;Value&quot;).Element(ns + &quot;Medium&quot;).Value,
                  Title = D.Element(ns + &quot;Title&quot;).Value,
                  Region = D.Element(ns + &quot;Region&quot;).Value,
                  PriceDisplay = D.Element(ns + &quot;Body&quot;).Value,
                  ListingId = D.Element(ns + &quot;ListingId&quot;).Value,
                  CloseDate = D.Element(ns + &quot;EndDate&quot;).Value,
                  BuyNow = D.Element(ns + &quot;BuyNowPrice&quot;).Value,
                  StartPrice = D.Element(ns + &quot;StartPrice&quot;).Value,
              };
              progressBar1.IsIndeterminate = false;
              progressBar1.Visibility = Visibility.Collapsed;
          }
  
          public class TradeItem
          {
              public string Region { get; set; }
              public string ListingId { get; set; }
              public string PriceDisplay { get; set; }
              public string Title { get; set; }
              public string ImageSource { get; set; }
              public string CloseDate { get; set;  }
              public string StartPrice { get; set; }
              public string BuyNow { get; set; }
          }
          // Run query string to pass LIstingID to next page.
      }
  }
  </code></pre>