I am current writing a small tool with Xamarin Form (Android) that takes some file content and displays them in some specific way. In these files i have some cross-links (e.g. jpeg-images) that should be embedded in the display of the file.
To get the main file i am using "CrossFilePicker.Current.PickFile()". It returns an "FileData" object, which allready has the main file contents, plus the URI of that file.
If there is a cross-link in that file i can assume that the linked file is in the same folder as the main file.
My idea (taking jpeg as example) to get the base-folder of the file and append the name of the jpeg and then open the image as stream:
ImagePath = Path.Combine(baseFolder.Trim(), imageFile.Trim());
try
{
fileStream = new FileStream(ImagePath, FileMode.Open, FileAccess.Read);
fileStream.DisposeWith(Disposables);
ImageSource = ImageSource.FromStream(() => fileStream);
ShowImage = true;
}
catch
{
// Ignore
}
Unfortunatelly FileStream failes, and claims it could not find the containing directory.
The path towards to JPG look like this:
/document/0F1E-120D/TestData/P1060371.jpg
The file path i get from the Picker is:
content://com.android.externalstorage.documents/document/0F1E-120D%3ATestData%2FTestFile.txt
Using that a an URI i can extract the local path:
/document/0F1E-120D:TestData/TestFile.txt
When removing the file name i get
/document/0F1E-120D:TestData
Obviously that path is invalid...
Any hint on how i can get a valid path i can feed into the FileStream for reading the file? Any more hints about that permissions i have to take care? Currently i have set READ_EXTERNAL_STORAGE