Hi,
I have a VB.net application that will save attachments to a directory
on my local pc. I need to run this component on our exchange 2003
server and also save the attachments to a local DIR. When the
component is run on the exchange 2003 server a wizard gui is
automatically started which wants to install Outlook 2003. The
component is using mapi to access the default inbox.
What do i need to do to convert this component to run on exchange 2003
server so that Outlook 2003 doesnt need to be installed? Do you have
any suggestions?
here is the code used in the component:
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents btnSave As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.btnSave = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'btnSave
'
Me.btnSave.Location = New System.Drawing.Point(112, 24)
Me.btnSave.Name = "btnSave"
Me.btnSave.TabIndex = 0
Me.btnSave.Text = "SaveNow"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.btnSave)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnSave.Click
SaveAttachments("")
End
End Sub
Public Function SaveAttachments(ByVal PathName As String) As
Boolean
Dim oOutlook As Outlook.Application
Dim oNs As Outlook.NameSpace
Dim oInbox As Outlook.MAPIFolder
Dim oMessage As Outlook.MailItem
Dim oAttachment As Outlook.Attachment
Dim oItems As Outlook.Items
Dim iCtr As Integer
Dim iAttachCnt As Integer
On Error GoTo ErrHandler
GetTempDir()
sPathName = "E:\Temp\"
If sPathName.Substring(sPathName.Length - 1) <> "\" Then
sPathName = sPathName & "\"
If Dir(sPathName, vbDirectory) = "" Then Exit Function
oOutlook = New Outlook.Application
oNs = oOutlook.GetNamespace("MAPI")
oNs.Logon("", "", False, True)
oInbox =
oNs.GetDefaultFolder(Outlook.OlDefaultFolders.olFo lderInbox)
oItems = oInbox.Items
Dim i As Integer
oItems = oItems.Restrict("[Attachment] = true")
'oItems = oItems.Restrict("[Read] = true") 'This will read
'Unread' messages
For i = 1 To oItems.Count
oMessage = oItems.Item(i)
With oMessage.Attachments
iAttachCnt = .Count
If iAttachCnt > 0 Then
For iCtr = 1 To iAttachCnt
.Item(iCtr).SaveAsFile(sPathName &
..Item(iCtr).FileName)
Next iCtr
End If
End With
Next
SaveAttachments = True
Exit Function
ErrHandler:
MsgBox(Err.Description, MsgBoxStyle.Critical, Err.Number & "
" & "bye-bye")
oMessage = Nothing
oInbox = Nothing
oNs = Nothing
oOutlook = Nothing
End Function
Public Function GetTempDir() As String
Dim strDLL As System.Reflection.Assembly
sPathName = strDLL.GetExecutingAssembly().Location
sPathName = sPathName.Substring(0,
sPathName.LastIndexOfAny("\") + 1)
'above gives DIR of \BIN\ dir
GetTempDir = "C:\Scripts\SaveEmailAttachment\"
End Function
Public sPathName As String
End Class
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~
Thank you,
Fish