I have my READ_EXTERNAL_STORAGE permissions flagged in my Android Manifest. I have checked my Android phone (Android 7.0) and the file is definitely in the directory "/storage/emulated/0/Incoming/". However when I try to detect the file in Xamarin it says that it is not found. I do not receive an error since I check for it before trying to open it.
The string file shows a path and file name of "/storage/emulated/0/Incoming/item_list.csv" which is consistent to what I am looking for.
I have this installed on a ruggidized device and it works fine but for some reason when I want to test anything on my cellular Android device I get this issue.
I researched this on StackOverflow and most of the answers refereed to the path being incorrect. I changed path to include the AbsolutePath property but it did not work.
Thanks,
Mr.Rob
private string[] Load_Item_File()
{
string[] _result = new string[1000];
try
{
string path = Path.Combine((string)Android.OS.Environment.ExternalStorageDirectory, "Incoming");
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
_result[0] = "ERROR: DIRECTORY LOCKED";
return _result;
}
string file = Path.Combine((string)path, "item_list.csv");
if (!File.Exists(file))
{
_result[0] = "ERROR: FILE NOT FOUND";
return _result;
}
_result = File.ReadAllLines(file,encoding:Encoding.ASCII);
return _result;
}
catch (Exception ex)
{
string errorMessage = ErrorLog.CreateErrorMessage(ex);
ErrorLog.LogFileWrite(errorMessage);
_result[0] = "ERROR: ISSUE WHEN READING FILE";
return _result;
}
}