I have this lines in my code
var fileName = Guid.NewGuid().ToString();
localPath = Task.Run(() => dependency.SaveFileToDisk($"{fileName}.pdf", bytes)).Result;
But when i get to these lines it throws an exception
File must be corrupt or not exists
But i have fileName. Is needed some permission in the Andropid Manifest? Look, this line work with Android 10 very well.
This method is the problem
public async Task<string> SaveFileToDisk(string fileName, byte[] bytes)
{
if (!Directory.Exists(_rootDir)) Directory.CreateDirectory(_rootDir);
var filePath = Path.Combine(_rootDir, fileName);
File.WriteAllBytes(filePath, bytes);
return filePath;
}
I need some permission?
EDIT 1
A friend give me this to do
public bool SaveActivity(List<CheckListActivitiesByUser> model)
{
bool result = false;
try
{
string fileName = "Global1"; //Global.Storage.FileNameActivity;
string data = JsonConvert.SerializeObject(model);
Preferences.Set(fileName, data);
result = true;
}
catch(Exception ex)
{
string erro = ex.Message;
}
return result;
}
public List<CheckListActivitiesByUser> GetActivity()
{
List<CheckListActivitiesByUser> result = new List<CheckListActivitiesByUser>();
try
{
string fileName = Global.UsbMassStorageEnabled.FileNameActivity;
var data = Preferences.Get(fileName, string.Empty);
if(!string.IsNullOrEmpty(data))
{
result = JsonConvert.DeserializeObject<List<CheckListActivitiesByUser>(data));
}
}
catch(Exception ex)
{
string erro = ex.Message;
}
return result;
}
But i don't know what's CheckListActivitiesByUser. This is a model, correct, but what's model?
EDIT2
[Obsolete]
public async Task<string> SaveFileToDisk(string fileName, byte[] bytes)
{
if (!Directory.Exists(_rootDir))
Directory.CreateDirectory(_rootDir);
var filePath = Path.Combine(_rootDir, fileName);
File.WriteAllBytes(filePath, bytes);
return filePath;
}
Looking for my code when it is in this line
Directory.CreateDirectory(_rootDir);
I get the error. How can I solve this?