title: Netduino + Ethernet Shield: How to write to SD card?
body: <p>I have tried several example programs to write data to the SD card mounted on the <a href="http://arduino.cc/en/Main/ArduinoEthernetShield" rel="nofollow noreferrer">Ethernet shield</a>, but none worked. The SD card size is 4 GB and formatted as <a href="http://en.wikipedia.org/wiki/File_Allocation_Table#FAT32" rel="nofollow noreferrer">FAT32</a>.</p>
  
  <p>The Ethernet shield is the following:</p>
  
  <p>(Bought on Amazon - <a href="https://rads.stackoverflow.com/amzn/click/com/B0022TWQ22" rel="nofollow noreferrer" rel="nofollow noreferrer">Arduino Ethernet Shield</a>)</p>
  
  <p><img src="https://i.stack.imgur.com/Qmwk7.jpg" alt="Enter image description here"></p>
  
  <p>And this is example code that doesn't work when creating a Netduino application (not Netduino Plus application) (thefirst line throws an exception):</p>
  
  <pre><code>public static void Main()
  {
      StorageDevice.MountSD("SD1", SPI_Devices.SPI1, Pins.GPIO_PIN_D10);
  
      string[] directories = System.IO.Directory.GetDirectories(@"\");
      Debug.Print("directory count: " + directories.Length.ToString());
  
      for (int i = 0; i &lt; directories.Length; i++)
      {
          Debug.Print("directory: " + directories[i]);
      }
  
      string[] files = System.IO.Directory.GetFiles(@"\SD1");
      Debug.Print("file count: " + files.Length.ToString());
  
      for (int i = 0; i &lt; files.Length; i++)
      {
          Debug.Print("filename: " + files[i]);
          FileStream fs = new FileStream(files[i], FileMode.Open, FileAccess.Read, FileShare.None, 512);
          StreamReader sr = new StreamReader(fs);
          Debug.Print("contents: " + sr.ReadToEnd());
      }
  }
  </code></pre>
  
  <p>Is there a example working program?</p>
  
  <p><strong>Solution:</strong></p>
  
  <p>Thanks to Chris and James, I managed to write to the SD card and read from it. After putting everything together, <a href="http://mypetprojects.blogspot.com/2011/10/netduino-using-ethernet-shield-to.html" rel="nofollow noreferrer">I wrote an article</a>, in case anyone else faces the same issues.</p>