Creating Outlook Appointment from a .NET application

I've read the thread on the following topic,
Creating Outlook Task from a .NET application in order to create an Outlook Appt for a .NET Web Application.  I've gotten it to work as a console application, but not a web application.   I'm currently stuck.
I've created an Outlook profile, called "ASPNET" to access my inbox. (I"m developing on my machine).  I have "ASPNET" set as the default profile for when Outlook opens up.  But, I must be missing something else.  I'm currently getting the following error, "The server is not available. Contact your administrator if this condition persists."   This is happening when trying to login to the namespace.  I have no idea what server the message is talking about.  Can anyone help?  I've played around and also received the "can't login to MAPI when another MAPI login is happening" (or something like that).  I just can't seem to get past this Namespace Logon statement.  Please help...

Here's my code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        ' Create an Outlook application.
        Dim oApp As Outlook.Application = New Outlook.Application
       
        ' Get Mapi NameSpace and Logon.
        Dim oNS As Outlook.NameSpace = oApp.GetNamespace("MAPI")
        oNS.Logon("ASPNET", Missing.Value, False, True) ' TODO:

        ' Create an AppointmentItem.
        Dim oAppt As Outlook._AppointmentItem = oApp.CreateItem(Outlook.OlItemType.olAppointmentItem)
        'oAppt.Display(true)  'Modal      

        ' Change AppointmentItem to a Meeting.
        oAppt.MeetingStatus = Outlook.OlMeetingStatus.olMeeting

        ' Set some common properties.
        oAppt.Subject = "Created using OOM in VB.NET"
        oAppt.Body = "Hello World"
        oAppt.Location = "Samm E"

        oAppt.Start = Convert.ToDateTime("04/15/2004 9:00:00 AM")
        oAppt.End = Convert.ToDateTime("04/15/2004 1:00:00 PM")

        oAppt.ReminderSet = True
        oAppt.ReminderMinutesBeforeStart = 5
        oAppt.BusyStatus = Outlook.OlBusyStatus.olBusy  '  olBusy
        oAppt.IsOnlineMeeting = False
        oAppt.AllDayEvent = False

        ' Add attendees.
        Dim oRecipts As Outlook.Recipients = oAppt.Recipients

        ' Add required attendee.
        Dim oRecipt As Outlook.Recipient
        oRecipt = oRecipts.Add("DS Change Request Calendaar") ' TODO:
        oRecipt.Type = Outlook.OlMeetingRecipientType.olRequired

        '' Add optional attendee.
        'oRecipt = oRecipts.Add("UserTest2") ' TODO:
        'oRecipt.Type = Outlook.OlMeetingRecipientType.olOptional

        oRecipts.ResolveAll()

        'oAppt.Display(true)

        ' Send out request.
        oAppt.Send()

        ' Logoff.
        oNS.Logoff()

        ' Clean up.
        oApp = Nothing
        oNS = Nothing
        oAppt = Nothing
        oRecipts = Nothing
        oRecipt = Nothing
    End Sub
lbrtiesAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
My suggestion would be to put this line in the web.config file:

<identity impersonate="true" />
0
lbrtiesAuthor Commented:
I tried your suggestion, but it didn't work.
I have Outlook 2000 installed on my machine.  When I started the web application, Outlook was not running, however, I have the properties set to use the profile "ASPNET" as the default when Outlook opens.
I added the "Identity impersonate" line to the web.config file.
What happens is it seems to hangs on:

 Dim oApp As Outlook.Application = New Outlook.Application

After a few minutes, it comes back with a "Server execution failed" error.

I then tried it with Outlook open and running, again with "ASPNET" as the default profile.  Same thing happens.

I don't see any type of dialog box asking for information.  I thought there might be one that I can't see and the web page is hanging waiting for a user response.

Anyway, I then set the "Identity Impersonate" back to false and I'm back to where I started.  I had Outlook open when I run the application this time, and I get as far as the namespace logon and then receive the following error:

"Exception Details: System.Runtime.InteropServices.COMException: The server is not available. Contact your administrator if this condition persists."

I have no idea what server this error is talking about.

Any other ideas??
0
lbrtiesAuthor Commented:
Correction to my last comment.  I'm running Outlook 2002 sp1, not Outlook 2000.
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Bob LearnedCommented:
The ASP.NET security model is a very tricky beast!!!!!   Especially when dealing with COM objects.

PRB: "Access Denied" Error Message When You Call a Web Service While Anonymous Authentication Is Turned Off
http://support.microsoft.com/default.aspx?scid=kb;en-us;811318

PRB: "Access Denied" Error Message Occurs When You Impersonate an Account in ASP.NET and Then Call STA COM Components
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q325791

Bob
0
lbrtiesAuthor Commented:
Thanks.  I'll take a look.  I'll be out for a long weekend, so will get back to you sometime next Tuesday on whether this helped or not.

Note,  I was wondering if my company's proxy server was causing the problem.  I do have my Internet Options/Connections/Lan Settings set to Bypass the proxy server for local connections, though.

Gail
0
Bob LearnedCommented:
Does Outlook connect through the proxy to get to server on the outside?  Or is it on the inside?

Bob
0
lbrtiesAuthor Commented:
Hi,  I'm back from a long weekend.  In your question you ask "Does Outlook connect through the proxy to get to the server".  What server are you talking about?  The web server or the exchange server?  The web application will be inside our firewall, on our company's intranet.
0
lbrtiesAuthor Commented:
According to one of our network people, "Outlook is a client that directly connects to our Exchange servers.  The Outlook client is unaware of a Proxy Server."  Does this help?  
0
Bob LearnedCommented:
The web server in this case is the client that connects to the Exchange server.  Is the web server on the inside with the Exchange server, or does it connect through the firewall to the outside.

Bob
0
lbrtiesAuthor Commented:
Hi,
   Just wanted to let you know.  I was able to finally logon to the namespace.  My co-worker suggested the same thing you did, Bob, using <identity impersonate="true" /> , but with a username and password.  This did the trick.
   However, I"ve noticed that even though my code has the following lines in it:


 ' Logoff.
        oNS.Logoff()

        outlookApp.Quit()

        outlookApp = Nothing
        oNS = Nothing

The program leaves an instance of Outlook running after it's closed.
Any ideas?
0
Bob LearnedCommented:
COM:  Release Objects:

' Release the object through the COM interoperability.
System.Runtime.InteropServices.Marshal.ReleaseComObject(object)

' Force garbage collection.
GC.Collect

Remember to release all COM objects:  Application, worksheet, document, etc.

Bob
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.