jfversluis/FilePicker-Plugin-for-Xamarin-and-Windows

Could not find a part of the path "/content:/com.android.externalstorage.documents/document/6759-130B%3ANew%20Text%20Document.txt".

Closed this issue · 5 comments

Respected maintainers,
I have problem while using file picker in external/removal sdcard. It reads fine from internal storage. It pick file fine. But when I read from that path it raises that error.
118750301_899416500548416_5769764666336303097_n

I have both read and write permissions And also I ask user at runtime.

Expected Behavior

It should read file from external storage.

Actual Behavior

Raise error while reading file from picked file path.

Steps to Reproduce the Problem

  1. Pick a file
  2. And the start reading using File.ReadAllText

Specifications

  • NuGet package version: latest till now
  • Platform(s): android

@vividos

Update:
I am not developer But I guess this problem may be because of parsing path incorrectly.

I guess path should be like that
"storage/6759-130B%3ANew%20Text%20Document.txt"

Not like that
"/content:/com.android.externalstorage.documents/document/6759-130B%3ANew%20Text%20Document.txt"

Am I right ? If you need any information then ask me. I will surely cooperate.

118943057_742416182989286_3334596261760030440_n

Oh no ! Is there any workaround for that issue ? Else I will have to migrate.
https://github.com/jfversluis/FilePicker-Plugin-for-Xamarin-and-Windows#important

You need to use GetStream() and read the file from there, since when Android returns content:// URLs, you don't have a way to use a path.

Bro GetStream() isn't working. Could you please add compatibility layer for converting content url to path string ?
https://stackoverflow.com/a/47008332/11390822

Brother I found a workaround to convert sdcard path in correct manner.

//Rextester.Program.Main is the entry point for your code. Don't change it.
//Microsoft (R) Visual C# Compiler version 2.9.0.63208 (958f2354)
//https://stackoverflow.com/a/63873712/11390822

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace Rextester
{
    public class Program
    {
        public static void Main(string[] args)
        {
            string pattern = @".{4}-.{4}\/.*[\w\.]+$";
            Regex rgx = new Regex(pattern);
            string sentence = "/content:/com.android.externalstorage.documents/document/6759-130B/New Text Document.txt";

            foreach (Match match in rgx.Matches(sentence))
            {
                System.Console.WriteLine("storage"+match.Value);  //storage/6759-130B/New Text Document.txt
            }
        }
    }
}

And also another approach was to read using open stream and put to picture folder. Does this is correct manner to do ? https://stackoverflow.com/a/63861563/11390822

Yes, reading from the steam should work on all cases, since internally it uses the Content provider class. In the upcoming Xamarin.Essentials file picker, it is the only way to get access to the file.