Xamarin – Reading a Text file from SD Card in Android

In this post we would see how we can read a text file from SD Card in Android.

Make sure you have copied the text file to the SD Card. Follow these methods for copying the file to SD Card image.

  1. Using Eclipse DDMS Tool
  2. Using ADB.EXE
  3. Using WinImage Tool


Here is how the example would work. We would have a button in the layout; on click of that button, the file would be read and the content would be displayed in a TextView control.


The following layout design is having a Button and a TextView.


The resources used in above layout.


Now that, we have designed; let’s do the following code in OnCreate().

We would be using Environment class to get the SD Card path. Use Android.OS namespace for using the class.


Now in Button Click event handler, we would do the basic file reading operation.


Let’s run the application and see it’s in action. Yes, on click of the button the text from the file is displayed.

But the Text is not scrollable.


Making TextView Scrollable

Make changes to the TextView like the following and this should do the trick.


Well, now you can see the scrollbar in TextView.


Hope this helps thanks for reading.

Full Source Code: Click Here