Destroyer
Destroyer

Reputation: 679

How to write a Dictionary (collection) object to file (VB .Net 2010)

I am attempting to write a Dictionary Collection to a file.

The Collection is structured like so:

GlobalCollection    (Collection of TestCollection)
    (0)
    [KEY]
    [Value]
    - TotalGlobal_W_Count    (Integer)
    - TotalGlobal_I_Count    (Integer)
    - TotalGlobal_F_Count    (Integer)
    TestCollection    (Dictionary - Key, Value)
        (0)
        [KEY]
        [Value]
        - NumberOfTests        (Integer)
        - TestCollectionName    (String)
        - TypesOfTests        (ArrayList)
        ResultsCollection    (Dictionary - Key, Value)
            (0)
            [KEY]
            [Value]
            - TotalFcount    (Integer)
            - TotalIcount    (Integer)
            - TotalWcount    (Integer)
            - ID        (String)
            - TestFolderType(String)
            - TestPassed    (Boolean)
            - FullLog    (Array)
            ResultsCollection    (Dictionary - Key, Value)
                (0)
                [KEY]
                [Value]
                - LineNumber    (Integer)
                - MessageType    (String)
                - ResultString    (String)

I would like to write out all of the above variables to a text file while keeping the hierarchy formatting. (Note there can be number of elements in each collection object)

Thanks!!!

Upvotes: 2

Views: 5886

Answers (2)

GameAlchemist
GameAlchemist

Reputation: 19294

faster and smaller than xml, if you don't plan to parse/... the serialized file, is to use a BinaryFormater :

Dim MyFormatter As New BinaryFormatter()
Dim MyFile As New FileStream("Serialized.ser", FileMode.Create, FileAccess.Write, FileShare.None)
MyFormatter.Serialize(MyFile, TheObjectIWantToSerialize)
MyFile.Close()

Upvotes: 4

Joel Etherton
Joel Etherton

Reputation: 37533

Serialize it to Xml. Here is a StackOverflow question that answers the topic. An especially good read is the link by @John Saunders in the comments.

Upvotes: 3

Related Questions