Hi,
I have a WPF program that will go through all of the emails in a users inbox (outlook) and save all of the attachments to a specified folder (C:\Attachments)

What I want to do is to be able to select the folder within the Inbox to run the program on as it currently only works on the root of the inbox.

I have seen several snippets of code on sites such as MSDN but cannot get them to compile.

Does anyone know how I can point the function at a specific folder?

The code for the function is below.

Public Function SaveAttachments(ByVal PathName As String) As Boolean

Dim oOutlook As Outlook.Application
Dim oNs As Outlook.NameSpace
Dim oFldr As Outlook.MAPIFolder
Dim oMessage As Object
'Dim oAttachment As Outlook.Attachment()
Dim iCtr As Integer
Dim iAttachCnt As Integer
Dim sFileName As String

Try
oOutlook = New Outlook.Application
oNs = oOutlook.GetNamespace("MAPI")
'get Inbox folder
oFldr = oNs.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)

'browse the folder
For Each Message In oFldr.Items
With Message.Attachments
iAttachCnt = .Count
Progress(iAttachCnt & " attachments found")
If iAttachCnt > 0 Then
'if we have attachment
For iCtr = 1 To iAttachCnt
Try
sFileName = .Item(iCtr).FileName.ToString
.Item(iCtr).SaveAsFile(PathName & sFileName)
Progress("Saved " & sFileName)
Count += 1
Catch ex As System.Exception
'do nothing
End Try
Next iCtr
End If
End With
'Application.DoEvents()
System.Windows.Forms.Application.DoEvents()

Next Message
Return True
Catch ex As System.Exception
errormessage = ex.Message
Return False
Finally
oMessage = Nothing
oFldr = Nothing
oNs = Nothing
oOutlook = Nothing
Progress("All attachments saved")
ProgressText.Text = ProgressText.Text & vbNewLine 'a blank line to separate the runs.
End Try

End Function


Any help with this would be greatly appreciated.

Thanks

Gimbal