title: Xamarin android save text file
body: <p>I am using Xamarin.Android and I want to save a <code>.txt</code> file to the SD card. Here is the code that I am using:</p>
  
  <pre><code>  private void SavetoSd()
    {
         var sdCardPath = Android.OS.Environment.ExternalStorageDirectory.Path;
         var filePath = System.IO.Path.Combine(sdCardPath, "iootext.txt");
         if (!System.IO.File.Exists(filePath))
         {
             using(System.IO.StreamWriter write = new System.IO.StreamWriter(filePath,true))
             {
                 write.Write(etSipServer.ToString());
             }
         }    
    }
  </code></pre>
  
  <p>However, I receive the following error:</p>
  
  <blockquote>
    <p>System.UnauthorizedAccessException: Access to the path
    "/mnt/sdcard/iootext.txt" is denied.</p>
  </blockquote>
  
  <p>I have added the following to the manifest:</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
  &lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /&gt;
  </code></pre>
  
  <p>How can I fix the error?</p>