Link to home
Start Free TrialLog in
Avatar of aeromatt
aeromatt

asked on

C#.Net - "Access is denied" error when trying to create and send Outlook Appointment Item

I am trying to interface with the Microsoft Outlook 11.0 Object Library within my C#.Net web application in order to programmatically create an Outlook Appointment Item and send it.  I have added a reference to the Outlook Object Library.

Here is my code:
private void Button1_Click(object sender, System.EventArgs e)
            {
                  Outlook._Application outapp = new Outlook.ApplicationClass();
                  Outlook._AppointmentItem outitem = (Outlook._AppointmentItem)outapp.CreateItem(Outlook.OlItemType.olAppointmentItem);

                  Outlook.Recipient myrecip = (Outlook.Recipient)outitem.Recipients.Add("myemailaddress");
                  
                  outitem.Start = new System.DateTime(2004,10,20,11,30,00);
                  outitem.End = outitem.Start.AddHours(2);
                  outitem.Subject = "class";
                  outitem.Location = "conference";
                  outitem.Body = "class";
                  outitem.ReminderMinutesBeforeStart = 15;
                  outitem.Save();
                  outitem.Send();
            }

I am getting an "Access is Denied"  error coming from this line:
Outlook._Application outapp = new Outlook.ApplicationClass();

I also get this semi-generic message:
ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.

To grant ASP.NET write access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.

I understand that I have not given the right access to the aspnet thread to some file, but I need to know what file it is that I need to change the security permissions of???

I have changed the permissions for the aspnet thread for the msoutl.olb file that as far as I know is the COM object that should be getting used here.

What am I doing wrong?

Thanks in advance.
ASKER CERTIFIED SOLUTION
Avatar of steve_bagnall
steve_bagnall

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial