Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full working Sample #10

Open
dernippel opened this issue Nov 17, 2017 · 20 comments
Open

Full working Sample #10

dernippel opened this issue Nov 17, 2017 · 20 comments
Assignees
Labels
Milestone

Comments

@dernippel
Copy link

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?

@Aragas
Copy link
Member

Aragas commented Nov 20, 2017

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

@step4
Copy link

step4 commented Nov 20, 2017

I am using something like:

_rootFolder = new DocumentsRootFolder()

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

@DNF-SaS
Copy link

DNF-SaS commented Nov 23, 2017

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

@Aragas
Copy link
Member

Aragas commented Nov 23, 2017

We have a pull request that I hope should fix UWP

@Aragas
Copy link
Member

Aragas commented Nov 27, 2017

Should be working with 1.3.2 now

@DNF-SaS
Copy link

DNF-SaS commented Nov 29, 2017

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

@Aragas
Copy link
Member

Aragas commented Nov 29, 2017

Can you provide the code that crashes on Android?

@DNF-SaS
Copy link

DNF-SaS commented Nov 29, 2017

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();

@Aragas
Copy link
Member

Aragas commented Nov 29, 2017

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

@DNF-SaS
Copy link

DNF-SaS commented Nov 29, 2017

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

@Aragas
Copy link
Member

Aragas commented Nov 29, 2017

I guess the DocumentsRootFolder and the LocalRootFolder

@DNF-SaS
Copy link

DNF-SaS commented Nov 29, 2017

DocuementsRootFolder works with 1.3.1 on Android but 1.3.2 crashes.

@Aragas
Copy link
Member

Aragas commented Nov 29, 2017

Interesting. Code to reproduce?

@DNF-SaS
Copy link

DNF-SaS commented Nov 30, 2017

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

@Aragas
Copy link
Member

Aragas commented Dec 1, 2017

Strange issue. Should work in both versions

@Aragas Aragas added the uwp label Jun 22, 2018
@Aragas Aragas added this to the Fix UWP milestone Jun 22, 2018
@ArtjomP
Copy link
Collaborator

ArtjomP commented Jun 27, 2018

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.

@imhrushi
Copy link

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.

@Aragas
Copy link
Member

Aragas commented May 24, 2019

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

@imhrushi
Copy link

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.

@Aragas
Copy link
Member

Aragas commented May 28, 2019

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants