title: How to Upload Any file from internal or External Storage in Xamarin?
body: <p>I have written code for Picking Image &amp; Uploading Image and getting a particular image with it's location in emulator but how do i access any file from Android File System using Xamarin so what should i use to do that ?.</p>
  
  <pre><code>namespace XAFileUpload_2._0
  {
      [Activity(Label = "XAFileUpload 2.0", MainLauncher = true, Icon = "@drawable/icon")]
      public class MainActivity : Activity
      {
  
          //Pick Id to know the pick item no.
          public static readonly int PickImageId = 1000;
  
          protected override void OnCreate(Bundle bundle)
          {
              base.OnCreate(bundle);
  
              // Set our view from the "main" layout resource
              SetContentView (Resource.Layout.Main);
  
              Button button = FindViewById&lt;Button&gt;(Resource.Id.Browse);
              button.Click += BrowseButtonOnClick;
  
          }
  
          void BrowseButtonOnClick(object sender, EventArgs eventArs)
          {
              Intent = new Intent();
              Intent.SetType("image/*");
              Intent data = Intent.SetAction(Intent.ActionGetContent);
  
              try
              {
                  StartActivityForResult(Intent.CreateChooser(Intent, "Select Picture"), PickImageId);
              }
              catch (ActivityNotFoundException ex)
              {
                  Toast.MakeText(this, "Please install a File Manager.", ToastLength.Long).Show();
              }
              catch (Exception ex)
              {
                  Toast.MakeText(this, "Error occured ", ToastLength.Long).Show();
              }
          }
  
          protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
          {
              if ((requestCode == PickImageId) &amp;&amp; (resultCode == Result.Ok) &amp;&amp; (data != null))
              {
                  UploadFile(data);
  
              }
          }
  
          void UploadFile(Intent data)
          {
              ICursor cursor = null;
  
              try
              {
                  Button upButton = FindViewById&lt;Button&gt;(Resource.Id.Upload);
  
                  // assuming image
                  var docID = DocumentsContract.GetDocumentId(data.Data);
                  var id = docID.Split(':')[1];
                  var whereSelect = MediaStore.Images.ImageColumns.Id + "=?";
                  var projections = new string[] { MediaStore.Images.ImageColumns.Data };
                  // Try internal storage first
                  cursor = ContentResolver.Query(MediaStore.Images.Media.InternalContentUri, projections, whereSelect, new string[] { id }, null);
                  if (cursor.Count == 0)
                  {
                      // not found on internal storage, try external storage
                      cursor = ContentResolver.Query(MediaStore.Images.Media.ExternalContentUri, projections, whereSelect, new string[] { id }, null);
                  }
                  var colData = cursor.GetColumnIndexOrThrow(MediaStore.Images.ImageColumns.Data);
                  cursor.MoveToFirst();
                  var fullPathToImage = cursor.GetString(colData);
                  string fpti = cursor.GetString(colData);
  
                  string address = "http://192.168.3.157:82/Values/DownFile";
  
  
                  upButton.Click += (sender, args) =&gt;
                  {
                      try
                      {
                          ProgressDialog progressDialog = new ProgressDialog(this);
                          progressDialog.SetTitle("Please wait...");
                          progressDialog.SetCancelable(false);
  
                          Task.Run(() =&gt;
                          {
  
                              RunOnUiThread(() =&gt;
                              {
                                  progressDialog.Show();
                              });
  
                              using (WebClient client = new WebClient())
                              {
                                  client.UploadFile(address, fullPathToImage);
  
                              }
  
                              RunOnUiThread(() =&gt;
                              {
  
                                  progressDialog.Dismiss();
  
                                  string msg = "Upload Completed";
                                  Toast.MakeText(this, msg, ToastLength.Long).Show();
  
                              });
                          });
                      }
                      catch (Exception ex)
                      {
                          Log.Error("MediaPath", ex.Message);
                      }
                  };
              }
              catch (Exception ex)
              {
                  Log.Error("MediaPath", ex.Message);
              }
              finally
              {
  
                  cursor?.Close();
                  cursor?.Dispose();
              }
          }
      }
  }
  </code></pre>