Android Question Select a file from File.DirRootExternal

David Hawkins

Active Member
Licensed User
Longtime User
Hi I'm sure this is quite simple unless you are me in which case I'm stuck. Simply put I can create an excel spreadsheet and save it into File.DirRootExternal folder then I want to select the file just created so that it can be attached to an email. I have tried contentChooser, but i want to see all the files in the File.DirRootExternal folder so how can I do that? I would very much appreciate some assistance with this issue please.
many regards
David
 
The problem likely stems from the fact that ContentChooser is not a file explorer.
It relies on a content provider (Documents, Downloads, Google Drive, etc.) and does not necessarily allow for direct browsing of `File.DirRootExternal`.

If you already know the filename, there is no need to use ContentChooser. You can attach the file directly to the email-sending intent.
If you want the user to be able to browse the storage and select a file, you will need to use a custom file explorer based on `File.ListFiles`.

For example, to list all files present in `File.DirRootExternal`:
B4X: Copy
Dim Files As List = File.ListFiles(File.DirRootExternal)
For Each f As String In Files
    Log(f)
Next
Then, display this list in a CustomListView, a B4XDialog, a ListView, etc., and let the user choose the file.

If the goal is simply to send the Excel file you have just created via email, it is generally easier to attach it directly rather than asking the user to select it again.
 
Upvote 0
File.DirRootExternal = broken code.
 
Upvote 0
The problem likely stems from the fact that ContentChooser is not a file explorer.
It relies on a content provider (Documents, Downloads, Google Drive, etc.) and does not necessarily allow for direct browsing of `File.DirRootExternal`.

If you already know the filename, there is no need to use ContentChooser. You can attach the file directly to the email-sending intent.
If you want the user to be able to browse the storage and select a file, you will need to use a custom file explorer based on `File.ListFiles`.

For example, to list all files present in `File.DirRootExternal`:
B4X: Copy
Dim Files As List = File.ListFiles(File.DirRootExternal)
For Each f As String In Files
    Log(f)
Next
Then, display this list in a CustomListView, a B4XDialog, a ListView, etc., and let the user choose the file.

If the goal is simply to send the Excel file you have just created via email, it is generally easier to attach it directly rather than asking the user to select it again.
Zed thank you for your quick reply. You have made me think a bit more about what I really want to achieve. I will try your code and get a better understanding of what I can do. Again thank you.
Regards
David
 
  • Like
Reactions: zed
Upvote 0
Back
Top