Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

File.WriteAllText not showing in android 'Files' but the file appears to be there um?

$
0
0

I am trying to save some data to file in my Xamarin.Forms app. The following code SaveText executes with out an exception. And appears to save the data.

However, when I look for the file on the android device I am debugging with. In the android 'Files' app the file does not show up.

In VS in the output window the following is output form the Debug.Writeline below when it looks like my file saves.
[0:] saving results to:
/data/user/0/com.mynextbook.mynextbook/files/.local/share/Global/MySeries.json

However, when I browse to this location on the android device. There is no directory 'com.mynextbook.mynextbook'

I have a corresponding read method that uses the same path to ready the path. And Wow the load method finds a file and loads it with data I expected.
[0:] LoadSeriesFromLocalFile:
/data/user/0/com.mynextbook.mynextbook/files/.local/share/Global/MySeries.json

So why can I not see the file in Android 'Files'?

Thanks
Brady

static void SaveText(string text)
{
try
{
var path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Global");

            if (!Directory.Exists(path))
                Directory.CreateDirectory(path);

            var filePath = Path.Combine(path, SessionFileName);
            File.WriteAllText(filePath, text, Encoding.UTF8);
            System.Diagnostics.Debug.WriteLine("saving results to:" + filePath);
        } catch (Exception ex)
        {
            System.Diagnostics.Debug.WriteLine("SaveText:" + ex.Message);

        }
    }

 public  static  ObservableCollection <Series>  LoadSeriesFromLocalFile()
    {
        var path = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData ), "Global");
        var filePath = Path.Combine(path, SessionFileName);
        var fileText = string.Empty;

        if (File.Exists(filePath))
        {
            fileText =  File.ReadAllText(filePath, Encoding.UTF8);
            System.Diagnostics.Debug.WriteLine("LoadSeriesFromLocalFile:" + filePath);
            SeriesJsonStringToClass(fileText);
        }
        return series;

    }

Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>