StreamReader and data types

  • Thread starter Thread starter Image Integration
  • Start date Start date
I

Image Integration

Hi,

How do I write and read e.g. DataTime values to a file ?
StreamReader/Writer, FileStream... does only support e.g. text, 16, 32
bit... but not other types (DateTime and so on !)

(e-mail address removed)
 
Ginny said:
You can write the DateTime value to a file using yourDateTime.ToString().

I know, but I need the values again. so I prefer the DateTime format.
 
Use the BitConverter to get the bytes, pass them through the steam, and then
convert them back to a DateTime
 
When you need to get the DateTime values back, use yourDateTime =
Convert.ToDateTime(yourString);

You should put a try...catch block around this code in case the string isn't
a valid DateTime.
 
I would use the filetime int (long) format - it serializes easily and takes
much less space than a string
 
Back
Top