Home All Groups Group Topic Archive Search About

Creating an appointment using CDO

Author
27 Apr 2007 12:45 PM
Patrick_Stählin
Hi!

I'm trying to create an appointment using CDO and C#. The target-system
runs a Exchange 2003 Server.

Using the code from kb310557 [0] (full code below) I was able to create
Appointments for the "Administrator" user. Changing the URL to point to
my test user ("tester") makes SaveToContainer throw the following
OLE-Exception:

"System.Runtime.InteropServices.COMException (0x80040E19): Object or
data matching the name, range, or selection criteria was not found
within the scope of this operation."

I suspected that's a Security problem, but if I supply the Username /
Password for tester (and the URL for testers MBX) I get a
"NonAutorized..." exception.
So it might be a config-issue, but as a non Exchange-Admin I'm pretty
lost on this.

Any clues?

[0] http://support.microsoft.com/kb/310557

With kind regards
Patrick Stählin

Code:
8<-8<-8<-8<-8<
using System;
using System.Collections.Generic;
using System.Text;

namespace CDOTest
{
   class Program
   {
     static void Main(string[] args)
     {
       try
       {
         string sURL =
"file://./backofficestorage/win2kdomain.test/MBX/Administrator/calendar";

         ADODB.Connection oCn = new ADODB.Connection();
         oCn.Provider = "exoledb.datasource";

         oCn.Open(sURL, "", "", 0);
         if (oCn.State == 1)
         {
           Console.WriteLine("Good Connection");
         }
         else
         {
           Console.WriteLine("Bad Connection");
         }

         CDO.Configuration iConfg = new CDO.Configuration();
         ADODB.Fields oFields;


         oFields = (ADODB.Fields)iConfg.Fields;
         oFields[CDO.CdoCalendar.cdoTimeZoneIDURN].Value =
CDO.CdoTimeZoneId.cdoParis;
         oFields.Update();

         CDO.Appointment oApp = new CDO.Appointment();

         oApp.Configuration = iConfg;
         oApp.StartTime = Convert.ToDateTime("27.04.2007 12:00:00");
         oApp.EndTime = Convert.ToDateTime("27.04.2007 13:00:00");
         oApp.Location = "My Cube";
         oApp.Subject = "Test Create App in C#";
         oApp.TextBody = "Hello...";

         oApp.DataSource.SaveToContainer(sURL, null,
           ADODB.ConnectModeEnum.adModeReadWrite,
           ADODB.RecordCreateOptionsEnum.adCreateNonCollection,
           ADODB.RecordOpenOptionsEnum.adOpenSource,
           "", "");

         oCn.Close();

         oApp = null;
         oCn = null;
         oFields = null;
       }
       catch (Exception e)
       {
         Console.WriteLine("{0} Exception caught.", e);
       }
     }
   }
}
8<-8<-8<-8<-8<

Author
27 Apr 2007 11:43 PM
Glen Scales [MVP]
That error means that part of the URL you are using isn't valid are you
using an International version of Exchange in this case you may find the
calendar folder's name is different from calendar and named in your local
language.  Have a look at
http://msdn2.microsoft.com/en-us/library/ms992623.aspx for a method you can
use to find the proper URL to use. Another easy way to tell if you using the
right URL is if you logon to OWA and right click open in new in the folder
list of the folder your trying to access this will display the path to the
folder tools like Exchange Explorer are also useful for testing permission's
and URL's outside of your code.

Cheers
Glen

Show quote
"Patrick Stählin" <patrick.staehlin_remove_@_remove_encodo.ch> wrote in
message news:4631f084$1_1@news.tiscalinet.ch...
> Hi!
>
> I'm trying to create an appointment using CDO and C#. The target-system
> runs a Exchange 2003 Server.
>
> Using the code from kb310557 [0] (full code below) I was able to create
> Appointments for the "Administrator" user. Changing the URL to point to my
> test user ("tester") makes SaveToContainer throw the following
> OLE-Exception:
>
> "System.Runtime.InteropServices.COMException (0x80040E19): Object or data
> matching the name, range, or selection criteria was not found within the
> scope of this operation."
>
> I suspected that's a Security problem, but if I supply the Username /
> Password for tester (and the URL for testers MBX) I get a
> "NonAutorized..." exception.
> So it might be a config-issue, but as a non Exchange-Admin I'm pretty lost
> on this.
>
> Any clues?
>
> [0] http://support.microsoft.com/kb/310557
>
> With kind regards
> Patrick Stählin
>
> Code:
> 8<-8<-8<-8<-8<
> using System;
> using System.Collections.Generic;
> using System.Text;
>
> namespace CDOTest
> {
>   class Program
>   {
>     static void Main(string[] args)
>     {
>       try
>       {
>         string sURL =
> "file://./backofficestorage/win2kdomain.test/MBX/Administrator/calendar";
>
>         ADODB.Connection oCn = new ADODB.Connection();
>         oCn.Provider = "exoledb.datasource";
>
>         oCn.Open(sURL, "", "", 0);
>         if (oCn.State == 1)
>         {
>           Console.WriteLine("Good Connection");
>         }
>         else
>         {
>           Console.WriteLine("Bad Connection");
>         }
>
>         CDO.Configuration iConfg = new CDO.Configuration();
>         ADODB.Fields oFields;
>
>
>         oFields = (ADODB.Fields)iConfg.Fields;
>         oFields[CDO.CdoCalendar.cdoTimeZoneIDURN].Value =
> CDO.CdoTimeZoneId.cdoParis;
>         oFields.Update();
>
>         CDO.Appointment oApp = new CDO.Appointment();
>
>         oApp.Configuration = iConfg;
>         oApp.StartTime = Convert.ToDateTime("27.04.2007 12:00:00");
>         oApp.EndTime = Convert.ToDateTime("27.04.2007 13:00:00");
>         oApp.Location = "My Cube";
>         oApp.Subject = "Test Create App in C#";
>         oApp.TextBody = "Hello...";
>
>         oApp.DataSource.SaveToContainer(sURL, null,
>           ADODB.ConnectModeEnum.adModeReadWrite,
>           ADODB.RecordCreateOptionsEnum.adCreateNonCollection,
>           ADODB.RecordOpenOptionsEnum.adOpenSource,
>           "", "");
>
>         oCn.Close();
>
>         oApp = null;
>         oCn = null;
>         oFields = null;
>       }
>       catch (Exception e)
>       {
>         Console.WriteLine("{0} Exception caught.", e);
>       }
>     }
>   }
> }
> 8<-8<-8<-8<-8<
Author
15 Oct 2007 3:51 PM
Pratyush Shukla
If it is not too late:

This error should only appear if the last two parameters(Exchange User ID and Password)  of SaveToContainer are blank, or are invalid.


EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com

AddThis Social Bookmark Button