Outlook app coded in VB.NET

crypto85

New member
Joined
Jul 29, 2004
Messages
1
Im trying to work with another mailbox (not the default one) in Outlook 2000. Ive constructed a way to read in a path from the visible folder in outlook. It reads in the path fine, does a string replace then an array split. The array split is the last spot where the program works. First, here is my code:

Imports System.IO
Imports System.Reflection
Imports System.Math

Module Module1

Sub Main()

Dim strFolderPath As String
Dim oApp As Outlook.Application
Dim oNS As Outlook.NameSpace
Dim colFolders As Outlook.Folders
Dim oFolder As Outlook.MAPIFolder
Dim arrFolders() As String
Dim i As Long

strFolderPath = "Mailbox CQ - Notify/Sent Items"

strFolderPath = Replace(strFolderPath, "/", "\")
arrFolders = Split(strFolderPath, "\")

Console.WriteLine(arrFolders(0))
Console.WriteLine(arrFolders(1))

oApp = New Outlook.Application
oNS = oApp.GetNamespace("MAPI")
oFolder = oNS.Folders.Item(arrFolders(0))

If Not oFolder Is Nothing Then
For i = 1 To UBound(arrFolders)
colFolders = oFolder.Folders
oFolder = Nothing
oFolder = colFolders.Item(arrFolders(i))
If oFolder Is Nothing Then
Exit For
End If
Next
End If

colFolders = Nothing
oNS = Nothing
oApp = Nothing
End Sub

End Module

The fatal error occurs on the oFolder = oNS.Folders.Item(arrFolders(0)). When I try to run the program, a "Unhandled exception of type System.Runtime.InteropServices.COMException occured in Console Application1.exe. Additional information: the operation failed. An object could not be found."

I checked Locals and arrFolders has a length of 2 with element 0 = Mailbox - CQ Notify and element 1 = Sent Items. Ive tried taking out the spaces thinking thay may cause it to break but it isnt. oFolder has a value of Nothing before the statement, and since the statement is never executed it has a value of Nothing when the program breaks.

I tried substituting strFolderPath for arrFolders(0)...no dice. Next I tried pasting in the text of the string in quotes for the value. The line still breaks. The code above is the project in its entireity, I made a seperate project to test this out.

Is there something else I need to import? Some additional COM module besides the one for Outlook I need to attach?

I attached a file of what the mailbox and folder look like in outlook.

Thanks a lot!!
 
Back
Top