4 Replies - 13592 Views - Last Post: 23 January 2010 - 11:52 AM Rate Topic: -----

#1 wads  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 11-January 10

Checking Outlook Folder exists

Posted 22 January 2010 - 04:38 PM

Hi,

I want to check if an Outlook folder exists, if it doesn't then create it & if it does then carry on with other code. I can create the folder as a sub folder of the Inbox but once it is created I get an error because it is still looking to create when it's already created.

I have tried to capture the error but still no joy.

Can anyone help?


  Dim objOutlook = New Outlook.Application
		Dim objNS As Outlook.NameSpace = objOutlook.GetNamespace("MAPI")
		Dim objEmail As Outlook.MailItem
		Dim objFolder As Outlook.MAPIFolder
		Dim objNewFolder As Outlook.MAPIFolder

		If objNewFolder Is Nothing Then

			objFolder = objNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
			objNewFolder = objFolder.Folders.Add("Service Reports", Outlook.OlDefaultFolders.olFolderInbox)

		End If


Is This A Good Question/Topic? 0
  • +

Replies To: Checking Outlook Folder exists

#2 Sethro117  Icon User is offline

  • Still the sexiest mofo.
  • member icon

Reputation: 236
  • View blog
  • Posts: 2,378
  • Joined: 14-January 09

Re: Checking Outlook Folder exists

Posted 22 January 2010 - 04:50 PM

Trying something like
If System.IO.Directory.Exists("path") Then
' do whatever here
Else
' Create directory
End If


This post has been edited by Sethro117: 22 January 2010 - 04:52 PM

Was This Post Helpful? 0
  • +
  • -

#3 wads  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 11-January 10

Re: Checking Outlook Folder exists

Posted 22 January 2010 - 05:50 PM

View PostSethro117, on 22 Jan, 2010 - 03:50 PM, said:

Trying something like
If System.IO.Directory.Exists("path") Then
' do whatever here
Else
' Create directory
End If



Thx for reply.

Not sure what I'd put in the 'path' though, (to outlook inbox- subfolder)?
Was This Post Helpful? 0
  • +
  • -

#4 Sethro117  Icon User is offline

  • Still the sexiest mofo.
  • member icon

Reputation: 236
  • View blog
  • Posts: 2,378
  • Joined: 14-January 09

Re: Checking Outlook Folder exists

Posted 22 January 2010 - 08:14 PM

Hmm, I didnt think about this. Outlooks information is stores in .pst file. Those are personal data files for your outlook account. As for where they are physically stored whether they are on the system or not I dont know. You might google around and see if you can find if the folder information is stores in those pst files or if by chance they are actually created physically somewhere on your system.
Was This Post Helpful? 0
  • +
  • -

#5 wads  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 11-January 10

Re: Checking Outlook Folder exists

Posted 23 January 2010 - 11:52 AM

View PostSethro117, on 22 Jan, 2010 - 07:14 PM, said:

Hmm, I didnt think about this. Outlooks information is stores in .pst file. Those are personal data files for your outlook account. As for where they are physically stored whether they are on the system or not I dont know. You might google around and see if you can find if the folder information is stores in those pst files or if by chance they are actually created physically somewhere on your system.

Solved it, used the code below
 'sets objFolder to the Inbox for it's reference
			objFolder = objNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)

			'Checks to see if Service Reports folders exists
			For i = 1 To objFolder.Folders.Count
				If objFolder.Folders.Item(i).Name = "Service Reports" Then
					GoTo MailSend
				End If
			Next
			'Creates folder in Outloook client inbox called Service Reports
			objNewFolder = objFolder.Folders.Add("Service Reports", Outlook.OlDefaultFolders.olFolderInbox)

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1