-
May 31st, 2012, 04:40 AM
#1
Thread Starter
Member
Outlook Folder Issue
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
-
May 31st, 2012, 04:56 AM
#2
Thread Starter
Member
Re: Outlook Folder Issue
Its OK......Panic over.
Solved it.
All i needed to do was to add a new variable:
Code:
Dim SubFolder as MAPIFolder
and then point it at the folder i wanted:
Code:
SubFolder = oFldr.Folders("Other")
and then use this in the loop rather then oFldr.
Hope this helps someone else with a similar problem.
Gimbal
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|