Filestream I/O on Nedtduino 3 Does Not Write to SD card

The following code write file to SD card on Netduino Plus 4.2 OK. But fails on ND3 4.3.
The code reads the file back under debug OK. But the file is empty on the SD card when opened in NotePad app .Please help.

public static void Main()
{ // reads from analog input port A0 and write to the file test.txt
const double maxVoltage = 3.3;
lightSensor.Scale = maxVoltage;
lightSensor.Offset = 0.0;
double voltagevalue = 0;

        using (var filestream = new FileStream(@"SD\test.txt", FileMode.OpenOrCreate))
        {

            StreamWriter streamWriter = new StreamWriter(filestream);
            for (int i = 0; i < 10; i++)
            { // use a 10k pot to trim the resistor value
                voltagevalue = lightSensor.Read();
                streamWriter.WriteLine("Light Level=" + voltagevalue.ToString() + DateTime.Now.ToString().ToString());
                Debug.Print(voltagevalue.ToString("f3"));
                Thread.Sleep(1000);

            }
            streamWriter.Flush();
            streamWriter.Close(); 

        }
        using (var filestream = new FileStream(@"SD\test.txt", FileMode.Open))
        {
            StreamReader reader = new StreamReader(filestream);    // reader object
            Debug.Print(reader.ReadToEnd());
            reader.Close();
            

        }


        
    }

Hi

This is some code which I chopped out of similar data logging application, I think you need to get the file system to flush as well

public class Program
 {
    public static void Main()
    {
       string fileName = DateTime.UtcNow.ToString("yyyyMMdd") + ".txt";
       Debug.Print(fileName);
       fileName = Path.Combine("\\sd", fileName);
       Debug.Print(fileName);
     
       while (true)
       {
          using (var file = new StreamWriter(fileName, true))
          {
             string line = DateTime.UtcNow.ToString("yyyy-MM-dd hh:mm:ss");
             file.WriteLine(line);
          }
          new Microsoft.SPOT.IO.VolumeInfo("\\sd").FlushAll();
     
          Thread.Sleep(5000);
       }
    }
 }

@KiwiBryn

Hello,
Thank you very much for your help. including the
new Microsoft.SPOT.IO.VolumeInfo("\sd").FlushAll();

Solved the problem.

Many thanks.
Hossein Kashani