Search code examples
c#xamarin.androidvisual-studio-2019

How to save the TextView.Text as text file in my Xamarin Android


I have the text in my Textview.Text I would like to save as a .textfile or worldfile in my Xamarin Android app(internally or externally) I have no idea how to do that please help me with your suggestions thanks in advance


Solution

  • About savind TextView.Text, I suggest you can learn about File Storage and Access with Xamarin.Android

    If you just want to save data into Internal storage, this space is not accessible except by the operating system or apps. Android will allocate a directory in the internal storage partition for each app. When the app is uninstalled, all the files that are kept on internal storage in that directory will also be deleted. Internal storage is best suited for files that are only accessible to the app and that will not be shared with other apps or will have very little value once the app is uninstalled.

    The following code is to save and read file into Internal storage.

     btn.Click += delegate
              {
                  fileName = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData), "temp.txt");
                  File.WriteAllText(fileName,text.Text );
              };
    
            btn1.Click += delegate
              {
                  var text = File.ReadAllText(fileName);
                  Console.WriteLine(text);
    
              };