views:

51

answers:

2

Hi all. In my contact manager program I have been storing information by reading and writing comma delimited files for each individual contact, and storing notes in a file for each note, and I'm wondering how I could go about shrinking them all into one file effectively. I have attempted using data entry tools in the visual studio toolbox and template class, though I have never quite figured out how to use them. What would be especially convenient is if I could store data as data type IOwner (a class I created) as opposed to strings.

I'd also need to figure out how to tell the program what to do when a file is opened (I've noticed in the properties how to associate a file type with the program though am not sure how to tell it what to do when it's opened).

Edit:

How about rephrasing the question: I have a class IContact with various properties some of them being lists of other class objects. I have a public list of IContact. Can I write Contacts as List(Of IContact) to a file as opposed to a bunch of strings?

Second part of the question: I have associated .cms files with my program. But if a user opens the file, what code should the program run through in an attempt to deal with the file? This file is going to contain data that the program needs to read, how do I tell it to read a file when the program is opened vicariously because the file was opened?

Does this make the question clearer?

A: 

IMHO, switch to sqlite. You'll be able to query faster, compress it, and much more then working with a csv file.

Am
I don't have one csv file, I have many, one for each contact, and a folder for notes which are stored in a text file for each note.This appears off hand to be a program as opposed to a tool for visual studios...and I'd have no idea how I could use it in my scenario...(personally i'd prefer to keep everything within the capabilities of the express edition I all ready have. They have data tools, I'm just not sure how to use them...)
Assimilater
A: 

Found this article about Serialization and it works very well!

http://www.vbdotnetheaven.com/UploadFile/Nimusoft/Serialization105022008052559AM/Serialization1.aspx

edit: Figured I should probably post more. I have a class IOwner, and list of this class contains all of my database. So I added serialization tags to this class and others it references then substitute in those properties with the ones shown on the article:

Imports System.Runtime.Serialization

Imports System.Runtime.Serialization.Formatters.Binary Imports System.IO Namespace BinarySerialization _ Public Class IFile Implements ISerializable Public Contacts As List(Of IOwner) Public Self As IOwner Public Cars As List(Of Vehicle) Public path As String Public Sub New()

    End Sub
    Public Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext)
        Data.Self = info.GetValue("Self", GetType(IOwner))
        Data.Contacts = info.GetValue("Contacts", GetType(List(Of IOwner)))
        Data.Cars = info.GetValue("Cars", GetType(List(Of Vehicle)))
    End Sub
    Public Sub WriteFile()
        Dim s As New FileStream(path, FileMode.Create, FileAccess.ReadWrite)
        Dim B As New BinaryFormatter()
        B.Serialize(s, Me)
        s.Close()
    End Sub
    Public Function ReadFile() As IFile
        Dim Fs As New FileStream(path, FileMode.Open, FileAccess.Read)
        Dim F As New BinaryFormatter()
        Dim s1 As IFile = DirectCast(F.Deserialize(Fs), IFile)
        Fs.Close()
        Return s1
    End Function

Region "ISerializable Members"

    Public Sub GetObjectData(ByVal info As SerializationInfo, ByVal context As StreamingContext) Implements ISerializable.GetObjectData
        info.AddValue("Self", Data.Self)
        info.AddValue("Contacts", Data.Contacts)
        info.AddValue("Cars", Data.Cars)
    End Sub

End Region

End Class

End Namespace

Assimilater