Solved

Object to array

Posted on 2016-10-12
7
28 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
  • 4
  • 3
7 Comments
 
LVL 49

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 49

Expert Comment

by:Ryan Chong
ID: 41841403
what info you wish to read from MailItem and put into JSON array ?
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

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 49

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 49

Accepted Solution

by:
Ryan Chong earned 500 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

759 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now