Hello,
Welcome to our Microsoft Q&A platform!
There are two ways to do ,using Internal Storage or setting the file hidden.
Internal Storageā this is a portion of the file system that can be accessed only by the application or the operating system.
I save a text file, you could refer to the following code
protected override void OnAppearing()
{
base.OnAppearing();
String str = "123456";//test
Byte[] byteArray = System.Text.Encoding.Default.GetBytes(str);
string fileName = "test.txt";
string documentPath = FileSystem.CacheDirectory;
string path = Path.Combine(documentPath, fileName);
File.WriteAllBytes(path, byteArray);
}
Create a hidden folder simply by adding a '.' to the front of the folder name.
I save the test.text file by External Storage , you could reder to the following code
private void Button_Clicked(object sender, EventArgs e)
{
String str = "123456";//test
Byte[] byteArray = System.Text.Encoding.Default.GetBytes(str);
string fileName = "test.txt";
String testPath = DependencyService.Get<PathService>().GetPath();
var folderPath = testPath + "/.test";
if (!Directory.Exists(folderPath))//creat a folder to save
{
DirectoryInfo dirInfor = new DirectoryInfo(folderPath);
dirInfor.Create();
}
var filePath = System.IO.Path.Combine(folderPath, fileName);
File.WriteAllBytes(filePath, byteArray);
}
use DependencyService to get path
public interface PathService
{
String GetPath();
}
Android
[assembly: Dependency(typeof(PathServiceAndroid))]
namespace AndroidStrogeDemo.Droid
{
public class PathServiceAndroid : PathService
{
public string GetPath()
{
string testPath = Android.App.Application.Context.GetExternalFilesDir("").AbsolutePath;
return testPath;
}
}
}
permission
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
However, you want to save video, internal storage directories tend to be small , your app should query the free space on the device before writing app-specific files to internal storage. If you create a hidden folder, user still can set "Don't show hidden files" or "Show hidden files". There is not a perfect way to do this, because this is the feature of Android.
Best Regards,
Wenyan Zhang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
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.