question

AnkushGupta-8648 avatar image
0 Votes"
AnkushGupta-8648 asked LeonLu-MSFT commented

Directory not created in android

string rootPath = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath + "/FolderName";
if (!File.Exists(rootPath))
Directory.CreateDirectory(rootPath);

Above code suddenly stop to create folder.

Please give some suggestions.

Thanks.

dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

LeonLu-MSFT avatar image
0 Votes"
LeonLu-MSFT answered LeonLu-MSFT commented

Hello,​

Welcome to our Microsoft Q&A platform!

On Android 10 (API level 29) and higher, your app's tests run in a storage sandbox by default. This sandbox prevents your app from accessing files outside of the app-specific directory and publicly-shared directories.

But you can write files or create folder in your application's path with following code.

string testPath= Android.App.Application.Context.GetExternalFilesDir("").AbsolutePath+ "/FolderName";

The new path is "/storage/emulated/0/Android/data/com.companyname.collectionviewdatatemple/files/FolderName"

Best Regards,

Leon Lu



If the response is helpful, please click "Accept Answer" and upvote it.

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.


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@AnkushGupta-8648 May I know if you have got any chance to check my answer? I am glad to help if you have any other questions.

0 Votes 0 ·
AnkushGupta-8648 avatar image
0 Votes"
AnkushGupta-8648 answered LeonLu-MSFT commented

Hi @LeonLu-MSFT

I resolved this issue by change Target Android Version to Android 10.0.


Thanks for help.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

You are welcome.

0 Votes 0 ·