简体   繁体   中英

How to save the TextView.Text as text file in my xamarin andriod

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

Use this:

File.WriteAllText (path, contents);

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);

          };

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM