title: How can I export data from listview(sqllite database) to txt file?
body: <p>I have data from the SQLite database and displayed it in the listview of Xamarin Forms. Now I want to export what's on my listview to a txt file on a particular Location.</p>
  <p>I have been searching on the internet but not getting any proper solution on it.</p>
  <p>This is the source for my binding.</p>
  <pre><code> &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;
    &lt;ContentPage xmlns=&quot;http://xamarin.com/schemas/2014/forms&quot;
           xmlns:x=&quot;http://schemas.microsoft.com/winfx/2009/xaml&quot;
           xmlns:local=&quot;clr-namespace:XamarinSQLite&quot;
           x:Class=&quot;XamarinSQLite.MainPage&quot;&gt;
  
  &lt;StackLayout&gt;
      &lt;StackLayout&gt;
          &lt;StackLayout HorizontalOptions=&quot;Center&quot; VerticalOptions=&quot;Start&quot;&gt;
              &lt;Image x:Name=&quot;imgBanner&quot; Source=&quot;banner.png&quot; &gt;&lt;/Image&gt;
              &lt;Image Margin=&quot;0,0,0,10&quot; HeightRequest=&quot;100&quot; Source=&quot;SQLite.png&quot; &gt;&lt;/Image&gt;
              &lt;Label Margin=&quot;0,0,0,10&quot; Text=&quot;SQLite&quot; FontAttributes=&quot;Bold&quot; FontSize=&quot;Large&quot; TextColor=&quot;Gray&quot; HorizontalTextAlignment=&quot;Center&quot; &gt;&lt;/Label&gt;
              &lt;Entry x:Name=&quot;txtPersonId&quot; Placeholder=&quot;PersonId Update and Delete&quot;&gt;&lt;/Entry&gt;
              &lt;Entry x:Name=&quot;txtName&quot; Placeholder=&quot;Enter Person Name&quot;&gt;&lt;/Entry&gt;
              &lt;StackLayout  HorizontalOptions=&quot;CenterAndExpand&quot; Orientation=&quot;Horizontal&quot;&gt;
                  &lt;Button x:Name=&quot;btnAdd&quot; WidthRequest=&quot;200&quot; Text=&quot;Add&quot; Clicked=&quot;BtnAdd_Clicked&quot; /&gt;
                  &lt;Button x:Name=&quot;btnRead&quot; WidthRequest=&quot;200&quot; Text=&quot;Read&quot; Clicked=&quot;BtnRead_Clicked&quot; /&gt;
              &lt;/StackLayout&gt;
              &lt;StackLayout HorizontalOptions=&quot;CenterAndExpand&quot; Orientation=&quot;Horizontal&quot;&gt;
                  &lt;Button x:Name=&quot;btnUpdate&quot; WidthRequest=&quot;200&quot; Text=&quot;Update&quot; Clicked=&quot;BtnUpdate_Clicked&quot;/&gt;
                  &lt;Button x:Name=&quot;btnDelete&quot; WidthRequest=&quot;200&quot; Text=&quot;Delete&quot; Clicked=&quot;BtnDelete_Clicked&quot; /&gt;
                  &lt;Button x:Name=&quot;btnExport&quot; WidthRequest=&quot;200&quot; Text=&quot;Export&quot; Clicked=&quot;btnExport_Clicked&quot; /&gt;
              &lt;/StackLayout&gt;
              &lt;ListView x:Name=&quot;lstPersons&quot;&gt;
                  &lt;ListView.ItemTemplate&gt;
                      &lt;DataTemplate&gt;
                          &lt;TextCell Text=&quot;{Binding Name}&quot; Detail=&quot;{Binding PersonID}&quot;&gt;&lt;/TextCell&gt;
                      &lt;/DataTemplate&gt;
                  &lt;/ListView.ItemTemplate&gt;
              &lt;/ListView&gt;
  
          &lt;/StackLayout&gt;
      &lt;/StackLayout&gt;
  &lt;/StackLayout&gt;
  </code></pre>
  
  <p><strong>Code Behind</strong></p>
  <pre><code>using System;
  using Xamarin.Forms;
  
  namespace XamarinSQLite
  {
      public partial class MainPage : ContentPage
      {
          public MainPage()
          {
              InitializeComponent();
          }
  
          protected async override void OnAppearing()
          {
              base.OnAppearing();
          
              //Get All Persons
              var personList = await App.SQLiteDb.GetItemsAsync();
              if(personList!=null)
              {
                  lstPersons.ItemsSource = personList;
              }
          }
  
          private async void BtnAdd_Clicked(object sender, EventArgs e)
          {
              if (!string.IsNullOrEmpty(txtName.Text))
              {
                  Person person = new Person()
                  {
                      Name = txtName.Text
                  };
  
                  //Add New Person
                  await App.SQLiteDb.SaveItemAsync(person);
                  txtName.Text = string.Empty;
                  await DisplayAlert(&quot;Success&quot;, &quot;Person added Successfully&quot;, &quot;OK&quot;);
                  //Get All Persons
                  var personList = await App.SQLiteDb.GetItemsAsync();
                  if (personList != null)
                  {
                      lstPersons.ItemsSource = personList;
                  }
              }
              else
              {
                  await DisplayAlert(&quot;Required&quot;, &quot;Please Enter name!&quot;, &quot;OK&quot;);
              }
          }
  
          private async void BtnRead_Clicked(object sender, EventArgs e)
          {
              if (!string.IsNullOrEmpty(txtPersonId.Text))
              {
                  //Get Person
                  var person = await App.SQLiteDb.GetItemAsync(Convert.ToInt32(txtPersonId.Text));
                  if(person!=null)
                  {
                      txtName.Text = person.Name;
                      await DisplayAlert(&quot;Success&quot;,&quot;Person Name: &quot;+ person.Name, &quot;OK&quot;);
                  }
              }
              else
              {
                  await DisplayAlert(&quot;Required&quot;, &quot;Please Enter PersonID&quot;, &quot;OK&quot;);
              }
          }
  
          private async void BtnUpdate_Clicked(object sender, EventArgs e)
          {
              if (!string.IsNullOrEmpty(txtPersonId.Text))
              {
                  Person person = new Person()
                  {
                      PersonID=Convert.ToInt32(txtPersonId.Text),
                      Name = txtName.Text
                  };
  
                  //Update Person
                  await App.SQLiteDb.SaveItemAsync(person);
  
                  txtPersonId.Text = string.Empty;
                  txtName.Text = string.Empty;
                  await DisplayAlert(&quot;Success&quot;, &quot;Person Updated Successfully&quot;, &quot;OK&quot;);
                  //Get All Persons
                  var personList = await App.SQLiteDb.GetItemsAsync();
                  if (personList != null)
                  {
                      lstPersons.ItemsSource = personList;
                  }
  
              }
              else
              {
                  await DisplayAlert(&quot;Required&quot;, &quot;Please Enter PersonID&quot;, &quot;OK&quot;);
              }
          }
  
          private async void BtnDelete_Clicked(object sender, EventArgs e)
          {
              if (!string.IsNullOrEmpty(txtPersonId.Text))
              {
                  //Get Person
                  var person = await App.SQLiteDb.GetItemAsync(Convert.ToInt32(txtPersonId.Text));
                  if (person != null)
                  {
                      //Delete Person
                      await App.SQLiteDb.DeleteItemAsync(person);
                      txtPersonId.Text = string.Empty;
                      await DisplayAlert(&quot;Success&quot;, &quot;Person Deleted&quot;, &quot;OK&quot;);
                  
                      //Get All Persons
                      var personList = await App.SQLiteDb.GetItemsAsync();
                      if (personList != null)
                      {
                          lstPersons.ItemsSource = personList;
                      }
                  }
              }
              else
              {
                  await DisplayAlert(&quot;Required&quot;, &quot;Please Enter PersonID&quot;, &quot;OK&quot;);
              }
          }
  
          private void btnExport_Clicked(object sender, EventArgs e)
          {
         //How to Export Data In Txt file
          }
      }
  }
  </code></pre>
  <p><strong>Please Help Me I am new in Xamarin</strong></p>