[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Object to array

Posted on 2016-10-12
7
Medium Priority
?
56 Views
Last Modified: 2016-11-07
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?
0
Comment
Question by:tonelm54
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 41839660
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
0
 

Author Comment

by:tonelm54
ID: 41841016
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?
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 41841403
what info you wish to read from MailItem and put into JSON array ?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:tonelm54
ID: 41841448
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).
0
 

Author Comment

by:tonelm54
ID: 41841452
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.
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 41841464
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.
0
 
LVL 53

Accepted Solution

by:
Ryan Chong earned 2000 total points
ID: 41841488
I come out with something like this, not too sure if this is useful for you.

Private Sub Test()
        Dim tempApp As Outlook.Application
        Dim tempInbox As Outlook.MAPIFolder
        Dim InboxItems As Outlook.Items

        tempApp = CreateObject("Outlook.Application")
        tempInbox = tempApp.GetNamespace("Mapi").GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
        InboxItems = tempInbox.Items

        Dim MailList As New List(Of MyMailItem)

        'Dim newMail As Outlook.MailItem
        For Each newMail In InboxItems
            If TypeOf newMail Is Outlook.MailItem Then
                'You may want to put some conditions here?
                If newMail.Subject.IndexOf("whatever") > 0 Then
                    Dim itm As New MyMailItem
                    itm.Subject = newMail.Subject
                    itm.ReceivedTime = newMail.ReceivedTime
                    itm.SenderName = newMail.SenderName
                    itm.SenderEmailAddress = newMail.SenderEmailAddress

                    For Each x As Outlook.Recipient In newMail.Recipients
                        Dim y As New MyRecipient()
                        y.Name = x.Name
                        y.EmailAddress = x.Address
                        itm.Recipient.Add(y)
                    Next
                    MailList.Add(itm)
                End If
            End If
        Next
        Dim serializer As New JavaScriptSerializer()
        Dim arrayJson As String = serializer.Serialize(MailList)
        MsgBox(arrayJson)
    End Sub

Open in new window

then you would need to have some classes like these:
Class MyRecipient
    Public Name As String
    Public EmailAddress As String
End Class

Class MyMailItem
    Public Subject As String
    Public ReceivedTime As String
    Public SenderName As String
    Public SenderEmailAddress As String
    Public Recipient As New List(Of MyRecipient)
End Class

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question