Unable to access Files(PDF) in Subfolder of Download folder of Android phone.

Raghavendra G R 121 Reputation points
2021-10-27T16:05:47.977+00:00

Hi,

I'm trying to access a pdf saved under "/storage/emulated/0/Download/Testfolder/sample.pdf"
ie Download/Testfolder (Subfolder in Downloads)

But i'm getting the path as below and hence unable to get the actual pdf file path
Wrong Path: /storage/emulated/0/Download/sample.pdf
Expected to get: /storage/emulated/0/Download/Testfolder/sample.pdf (As its store in a folder (Testfolder) under Downloads)

Target Framework: Android 11(R)

Any Xamarin android faced similar issue and found a solution please help.

Note: images in the same subfolder can be accessed without any issue.
Same issue i faced with 'Recent' folder of gallery

Regards,
Raghavendra

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,319 questions
0 comments No comments
{count} votes

2 additional answers

Sort by: Most helpful
  1. JarvanZhang 23,951 Reputation points
    2021-10-28T07:44:41.48+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    How do you create the file path, please make sure the sub folder exists on the divice. If the device doesn't have the folder, we need to create the sub folder first.

    Here is the sample code, you could refer to it.

       string filepath = System.IO.Path.Combine(Android.OS.Environment.ExternalStorageDirectory.AbsolutePath, Android.OS.Environment.DirectoryDownloads);  
       string the_path = System.IO.Path.Combine(filepath, "sub_folder");  
         
       if (!File.Exists(the_path))  
       {  
           Directory.CreateDirectory(the_path);  
       }  
       string fullName = System.IO.Path.Combine(the_path, fileName);  
         
       //handle the file  
    

    Best Regards,

    Jarvan Zhang


    If the response is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. Miguel Jesus ROMERO Ramos 0 Reputation points
    2024-06-08T16:38:39.9566667+00:00

    I can't open this file at all and I'm missing work like never before

    0 comments No comments