Main Site Documentation

Visual Basic: how to append data to an existing file on SD


#1

Hi,

I’m trying to log data in a file on SD, using a timer, for this I need to be able to APPEND data to an existing data file on the SD, however, it seems the append method is not available within Visual Basic…

So, right now I have following code, which re-creates the “data.txt” file every time.


Private Sub StorageTimer_Tick(timer As Gadgeteer.Timer) Handles StorageTimer.Tick
  ' Write to file
  Storage.GetStorageDevice.WriteFile("\data.txt", EncodedTxt)
End Sub

How to append?

Thanks,
Stefan


#2

The append option is accessed through the use of a FileStream object.


#3

something like:


Dim SDfile As System.IO.FileStream

SDfile = SDCard.Open(file,System.IO.FileMode.Append,System.IO.FileAccess.Write)
SDfile.Write(...data...)
SDfile.Close()


#4

James & Daniel,

Thank you very much, I got it working now!

Regards,
Stefan