Avatar of tonelm54
tonelm54
 asked on

Object to array

Is it possible to turn an object to an array in VB.net?

I have a object from outlook which is a mailitem, and I want to turn all the variables into an array to store in a file.

I know Ill loose the functionality of the object (such as move, copy etc) however i only want to store all the information in the object (in this case mailID, recipents etc).

Usually I could just count the elements and then copy the values one at a time, however the mailitem is a nested array inside a nested array inside a nested array so could be quite confusing.

Any ideas?
Visual Basic.NET

Avatar of undefined
Last Comment
Ryan Chong

8/22/2022 - Mon
Ryan Chong

I have a object from outlook which is a mailitem, and I want to turn all the variables into an array to store in a file.

yes, that's possible. you may want to consider to store it in a List(Of T) or look into the ToArray() method

List(Of T) Class
https://msdn.microsoft.com/en-us/library/6sh2ey19(v=vs.110).aspx
(look for the possible constructors and click on it to see the examples)

List<T>.ToArray Method ()
https://msdn.microsoft.com/en-us/library/x303t819(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1
tonelm54

ASKER
Couldnt get these to work :-(

So my code at the moment is:-
            Dim mail As Outlook.MailItem = item
            Dim output() As String = mail.toarray()

            Dim serializer As New JavaScriptSerializer()
            Dim arrayJson As String = serializer.Serialize(output)

            MsgBox(arrayJson)

Open in new window


Any ideas what Im doing wrong?
Ryan Chong

what info you wish to read from MailItem and put into JSON array ?
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
tonelm54

ASKER
Problem is, I dont know yet :-S

The data to store in the database (to search) keeps changing, so my plan was to store all the information in a JSON text file, then when a request comes along to add xxx to the search I can simply write some code to look at the JSON file and pull the requested field into the database and build the indexes for searching.

Initially they only wanted the `Date Received` and the `Subject`. Now its the `recipient` and `sender`, and already I've heard rumours they want the `conversationID` and Ive had requests to add `attachments` into the search. Hence store everything in a JSON text file and pull as needed, instead of trying to upload from the PST files again (which takes ages).
tonelm54

ASKER
So looking at the element for mail (which is a mailtem from outlook) I get the following elements:-
Untitled.png
I did think I could loop through each element and store in an array via:-
Dim objElement As Object
For Each objElement in mail

Next

Open in new window


But I cant figure a way of reading all the elements inside mail.
Ryan Chong

perhaps it doesn't make sense if we are looping through all the elements in mailtem since it's quite complex to read through all its content, as back to the basic, we only store useful info into database, and hence we only extract useful info from the source.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Ryan Chong

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.