1

I have seen many posts with similar issue as mine, but could not find solution for it. Hence I am posting the question specific my configurations.

I am developing a Xamarin android application which is supposed to create folder structure and files as show below:

Folder structure

The Test Folder would have mp3 files.

mp3 files

I want the user to be able to view all the files located under AppnName folder ie. abc.xml files and all the mp3 files inside test Folder

Here is my code:

var dir = new Java.IO.File(Android.OS.Environment.ExternalStorageDirectory.AbsolutePath + "/AppName/TestFolder");
if (!dir.Exists())
    dir.Mkdirs();

The above code works, it creates the folder structure, I could view all files from ES File Expolrer on my android device but once I connect the device to windows PC I can not view any of the files and folder.

I did some r&d and tries some of the solutions, but that did't help. I tried using media scan to scan the files as per the solution given here :https://stackoverflow.com/a/19934089/1650891. But it is not working for me.

Any help would be appreciated. Thanks in advance.

Community
  • 1
  • 1
Arti
  • 2,993
  • 11
  • 68
  • 121
  • `if (!dir.Exists()) dir.Mkdirs();`. Ckeck the return value as not always directories can be made. `if (!dir.Exists()) if (!dir.Mkdirs()) return;`. – greenapps Jul 21 '16 at 08:28
  • After switching the device off/on still not visible? – greenapps Jul 21 '16 at 08:29
  • Can you see the other files and folders on that card? A micro SD card? – greenapps Jul 21 '16 at 08:30
  • Strange. `ExternalStorageDirectory` mostly does not return a path to the micro SD card but to external memory. But you write to 35C3-13E6 which looks like the id for a removable medium. Do you see two drives op your pc? One for external and one for removable medium? – greenapps Jul 21 '16 at 08:36
  • Who created that `AppName` folder? – greenapps Jul 21 '16 at 08:38
  • No switching the device on/off doesn't work – Arti Jul 21 '16 at 09:02
  • Yes, I can see other folders and files created by other apps – Arti Jul 21 '16 at 09:03
  • No the device doesn't have micro SD card mounted. The `AppName` folder is created from the app. When I create a folder in my app creates a folder by the name of the app. `AppName` is the name of the app. – Arti Jul 21 '16 at 09:06

1 Answers1

2

I have managed to get it working. The trick here is to scan every new file created in the that directory. Every time I create a new file I follow it with below line of code.

MediaScannerConnection.ScanFile(Android.App.Application.Context, new String[] { path }, null, null);
Arti
  • 2,993
  • 11
  • 68
  • 121