title: Windows Mobile Professional 6.1 how to test internet connection
body: <p>I have a WM 6.1 Prof. application that checks updates when user wishes to do so.</p>
  
  <p>I want to check if there is any avaliable connection (GPRS or Wifi) before it attempts to connect to server.</p>
  
  <p>I am also using openNETCF.NET dll here is what I have done but it doesn't work everytime,</p>
  
  <p>also I am not sure which type of connection should I use and so.</p>
  
  <p>Ok do you think is this good? </p>
  
  <p>Thank you very much!</p>
  
  <pre><code>  private static HttpWebRequest ConnectWeb(string urlx)
    {
  
        try
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(urlx));
  
            request.ContentType = @"application/octet-stream";
            request.Credentials = CredentialCache.DefaultCredentials;
            request.Timeout(6000);
            return request;
        }
        catch (Exception ex)
        {
            MessageBox.Show(Lang.CONNECTIONPROBLEM);
            return null;
        }
    }
  
  
      private bool downloadTest()
      {
  
          Stream stream;
          HttpWebResponse response;
          HttpWebRequest request = ConnectWeb(FileManager.url);
          if (request!=null)
          {
              try
              {
  
                  using (response = (HttpWebResponse)request.GetResponse())
                  {
  
                      using (stream = response.GetResponseStream())
                      {
                          byte[] data = ReadFully(stream, (int)response.ContentLength);
                          writeByteArrayToFile(data, "data.zip");                                           
                      }                  
                  }
  
                  response.Close();
                  stream.Close();
  
              }
              catch (Exception ex)
              {
                  MessageBox.Show(Lang.CONNECTIONPROBLEM);
                  return false;
              }
  </code></pre>
  
  <p>}</p>