title: Unauthorized access while copying files onto USB via OTG Xamarin Android
body: <p>I am writing a code to paste files onto the USB Sandisk pen drive connected to my android KitKat device using an <strong>OTG</strong> cable.</p>
  
  <p>I am using the following code snippet.</p>
  
  <p>Using the following code I get a popup asking permission and on allowing it the <em>mUsbManager.HasPermission(device)</em>; returns true, but while i copy the file I get an Unauthorized access exception.</p>
  
  <p>I have set the <strong>WRITE_EXTERNAL_STORAGE</strong> permission.</p>
  
  <blockquote>
    <p>//Code Snippet</p>
  </blockquote>
  
  <pre><code>UsbManager manager = (UsbManager)_mainActivity.GetSystemService(Context.UsbService);
  var deviceList = manager.DeviceList;
  IEnumerable deviceIterator = deviceList.Values.AsEnumerable();
  
  if (deviceIterator.Count() &gt; 0)
  {
  var device = deviceIterator.ElementAt(0);
  
  ACTION_USB_PERMISSION = "com.android.example.USB_PERMISSION";
  var mPermissionIntent = PendingIntent.GetBroadcast(_mainActivity.ApplicationContext, 0, new Intent(ACTION_USB_PERMISSION), 0);
  
  UsbManager mUsbManager = (UsbManager)_mainActivity.GetSystemService(Context.UsbService);
  mUsbManager.RequestPermission(device, mPermissionIntent);
  
  bool perm = mUsbManager.HasPermission(device);
  if (perm)
  {
      string FileNameSource = "/storage/emulated/0/FileNotPresent.txt";
      string FileNameDestination = "/storage/2A85-5687/FileNotPresent.txt"; 
  
      File.Copy(FileNameSource, FileNameDestination);
  }
  }
  </code></pre>
  
  <p>Second question how can i get the path for the connected USB that as of now i have hard coded into the <strong>FileNameDestination</strong> variable.</p>
  
  <p>A sample code snippet will really be helpful. Thanks.</p>