title: How to get actual path from Uri xamarin android
body: <p>I want to get actual path from Uri, when I select file using intent then it will be returning URI but below line of code not working for conversion URI to string path</p>
  
  <p><strong>Open FilePicker</strong></p>
  
  <pre><code>public static void PickFile(Activity context)
  {
      Intent intent = new Intent(Intent.ActionGetContent);
      intent.SetType("*/*");
      context.StartActivityForResult(intent, PICKFILE_RESULT_CODE);
  }
  </code></pre>
  
  <p><strong>Get Result</strong></p>
  
  <pre><code>protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
  {
      if(requestCode == PICKFILE_RESULT_CODE)
      {
          string filepath = GetRealPathFromURI(MainActivity.act, data.Data);
      } 
  }
  
  public static string GetRealPathFromURI(Activity act, Android.Net.Uri contentURI)
  {
      try
      {
          ICursor cursor = act.ContentResolver.Query(contentURI, null, null, null, null);
          cursor.MoveToFirst();
          string documentId = cursor.GetString(0);
          documentId = documentId.Split(':')[1];
          cursor.Close();
  
          cursor = act.ContentResolver.Query(
          MediaStore.Images.Media.ExternalContentUri,
          null, MediaStore.Images.Media.InterfaceConsts.Id + " = ? ", new[] { documentId }, null);
          cursor.MoveToFirst();
          string path = cursor.GetString(cursor.GetColumnIndex(MediaStore.Images.Media.InterfaceConsts.Data));
          cursor.Close();
  
          return path;
      }
      catch(Exception e)
      {
          Log.Debug("TAG_DATA",e.ToString());
          return "";
      }
  }
  </code></pre>
  
  <p><strong>Error</strong></p>
  
  <blockquote>
    <p>System.IndexOutOfRangeException: Index was outside the bounds of the
    array.</p>
  </blockquote>
  
  <p>can anyone explain to me, what's wrong think I am doing in this code.</p>