Results 1 to 4 of 4

Thread: FileIO in .NET?

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2003
    Posts
    47

    FileIO in .NET?

    Hi. In dos based c++,i've done something like reading/writing a structure to a file. Is this possible with VB.NET? I've would like to save an object(probably a class) or even multiple object to a file and retrieve it's binary data and cast it back to an object.

    For eg. if i have a class:

    Public Class Student
    Public Name As String
    Public Age As Integer
    Public DateOfBirth As Date
    Public Religion As ReligionConstant
    End Class

    And I have few objects of the Student:

    Dim Matty As New Student()
    Dim Steven As New Student()
    Dim Jay As New Student()

    Matty.Name = "Matty"
    Matty.Age = 12
    Matty.DateOfBirth = "#12/5/2003#"
    Matty.Religion = ReligionConstant.Christian

    Steven.Name = "Steven"
    Steven.Age = 21
    Steven.DateOfBirth = "#12/5/2003#"
    Steven.Religion = ReligionConstant.Christian

    Jay.Name = "Jay"
    Jay.Age = 35
    Jay.DateOfBirth = "#9/9/2003#"
    Jay.Religion = ReligionConstant.Christian

    I would like to save these information into a file using binary format (not text) and need to know how to read these info and cast it back to an object. Thanks in advance.

    Archaven

  2. #2
    Banned
    Join Date
    Jul 2003
    Location
    New delhi
    Posts
    143
    to read and write the binary data the example is

    import system.io
    dim fs as filestream = new filestream("data.dat",filemode.open)
    dim mybinaryreader as binaryreader = new binaryreader(fs)
    dim buffer(1000) as byte
    mybinaryreader.rad(buffer,0,1000)


    Like this .if u can say i write the full program.but i think it give u idea.


    Biswajit das

  3. #3
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    Check out "Serialization" in the help index. That tells you how to write class data to either binary or XML files.

  4. #4
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Yeah Serialize is great for taking collections and arrays and saving them out to file

    I have a C# example here
    http://www.planet-source-code.com/vb...=186&lngWId=10

    Since you said you know C++, you shouldnt have any problem with the above code since C# is baically the same as VB.NET using C style syntax.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width