PCLExt.FileStorage icon indicating copy to clipboard operation
PCLExt.FileStorage copied to clipboard

Full working Sample

Open dernippel opened this issue 8 years ago • 20 comments

Hi,

I tried to replace PCLStorage with PCLExt.FileStorage and found the JSON and Log examples, but I didn't get it working.

I want to do something like:

var rootFolder = new ApplicationRootFolder();
await rootFolder.CreateFolderAsync(FileStoreConstants.TmpFolderName, CreationCollisionOption.OpenIfExists);

But I always get a NullReference Exception on rootFolder.

I'm using a Xamarin.Forms Solution with UWP, Android, iOS and .netstandard2.0 libararies (refer to the latest Prism Template Pack). I also tried to instantiate the root folder directly in the several platform project without success. The library is installed via nuget in the main project, the three platform projects (UWP, Android, iOS) and one or two libraries.

What I'm doing wrong? Is it possible to get a full working sample solution?

dernippel avatar Nov 17 '17 13:11 dernippel

ApplicationRootFolder is not supported on all platforms. It's working on iOS, but not Android or UWP. The UWP should work in theory, but it's not supported from the code right now, I'm investigating some strange permission issues

Aragas avatar Nov 20 '17 12:11 Aragas

I am using something like:

_rootFolder = new DocumentsRootFolder()

and I'm getting a path I can work with. Maybe that can help.

step4 avatar Nov 20 '17 15:11 step4

Same problem here on UWP - Android and iOS are working without problems. Using Version 1.3.1 from NuGet.

DNF-SaS avatar Nov 23 '17 14:11 DNF-SaS

We have a pull request that I hope should fix UWP

Aragas avatar Nov 23 '17 15:11 Aragas

Should be working with 1.3.2 now

Aragas avatar Nov 27 '17 21:11 Aragas

1.3.2 crashes on Android and throws an UnauthorizedAccessException on UWP. :-(

DNF-SaS avatar Nov 29 '17 08:11 DNF-SaS

Can you provide the code that crashes on Android?

Aragas avatar Nov 29 '17 11:11 Aragas

Sure, here - crash in the 2nd line.

var rootFolder = new ApplicationRootFolder(); var folder = await rootFolder.CreateFolderAsync(MetaService, CreationCollisionOption.OpenIfExists); if ( !await this.CheckFileExistsAsync(folder, ServiceRequestDraftJson) ) return null;

var draftFile = await folder.GetFileAsync(ServiceRequestDraftJson); var json = await draftFile.ReadAllTextAsync();

DNF-SaS avatar Nov 29 '17 11:11 DNF-SaS

ApplicationRootFolder is not supported on all platforms.
It's working on iOS, but not Android or UWP

Aragas avatar Nov 29 '17 11:11 Aragas

@Aragas thanks for die fast reply. Which IFolder-Implementation is supported on all platforms?

DNF-SaS avatar Nov 29 '17 12:11 DNF-SaS

I guess the DocumentsRootFolder and the LocalRootFolder

Aragas avatar Nov 29 '17 13:11 Aragas

DocuementsRootFolder works with 1.3.1 on Android but 1.3.2 crashes.

DNF-SaS avatar Nov 29 '17 16:11 DNF-SaS

Interesting. Code to reproduce?

Aragas avatar Nov 29 '17 19:11 Aragas

@Aragas Same code as yesterday - only ApplicationRootFolder replaced by DocumentsRootFolder.

DNF-SaS avatar Nov 30 '17 07:11 DNF-SaS

Strange issue. Should work in both versions

Aragas avatar Dec 01 '17 14:12 Aragas

Use LocalRootFolder to store your app data or RoamingRootFolder (in case you need roaming) or TempRootFolder (for temp files). You can't get access to DocumentsRootFolder msdn without special permission. I'm not sure about the ApplicationRootFolder for UWP I believe it's only for reading.

ArtjomP avatar Jun 27 '18 15:06 ArtjomP

When I use LocalRootFolder, it gives the path as, /storage/emulated/0/Android/data/com.companyname.AppName

But generally all the apps folders are under /storage/emulated/0 How to get access to this root folder? I want to create my app folder in this root folder.

Just as example if I use MusicRootFolder, it properly gives /storage/emulated/0/Music path.

imhrushi avatar May 23 '19 11:05 imhrushi

@imhrushi you could try new FolderFromPath("/storage/emulated/0")

Aragas avatar May 24 '19 09:05 Aragas

Thanks Aragas, I was able to use that folderfrompath. But now when I try to create a folder using that class object, it gives me error access denied. I suppose I have to check and ask for the runtime storage permissions? the code on the net for this needs Xamarin.Android.Support.Compat package and in turn that needs monoandroid framework. Now my xamarin forms in visual studio does not have this framework. Do I need to download it and install in order to do this all stuff? In the localrootfolder I have mentioned above, I am able to create a folder. It does not give access denied error. So I am curious.

imhrushi avatar May 28 '19 11:05 imhrushi

@imhrushi check first if your app has read&write permissions for external storage. If you have, then maybe you need to ask for the actual permissions from the user. Check this library for a sample https://github.com/jamesmontemagno/PermissionsPlugin/blob/master/README.md

Aragas avatar May 28 '19 12:05 Aragas