Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsWindows Server 2003Windows 2000Windows NTSmall Business ServerVirtual ServerExchange ServerIISHost Integration ServerISA ServerSMSWSUSMOMWindows Media ServerSecurityCertification
Related Topics
SQL ServerMS WindowsMS OfficePC HardwareMore Topics ...

Windows Server Forum / Exchange Server / Applications / September 2005

Tip: Looking for answers? Try searching our database.

exchange 2003 *Save Attachments*

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
fish - 07 Sep 2005 15:17 GMT
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.olFolderInbox)
       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
Tom Rizzo [MSFT] - 10 Sep 2005 21:59 GMT
Use CDO for Exchange, not the Outlook Object Model.  That should not prompt
for Outlook and is supported from .NET.

Tom

Signature

Looking for a good book on programming Exchange, Outlook, ADSI and
SharePoint?  Check out http://www.microsoft.com/MSPress/books/5517.asp

> Hi,
>
[quoted text clipped - 131 lines]
> Thank you,
> Fish
fish - 11 Sep 2005 14:32 GMT
Thanks I will look into this.

Tom B.

>Use CDO for Exchange, not the Outlook Object Model.  That should not prompt
>for Outlook and is supported from .NET.
>
>Tom
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.