locked
[EWSMA] 1.1 [C#] [E2007SP2] - Create Appointment in Public Folder Calendar RRS feed

  • Question

  • Hello,

    I am attempting to write code to insert appointments in a Public Folder Calendar.  I have Exchange 2007 Server SP2 (Versioned to 1 in the code), and my development platform is Visual Studio 2010, .NET 4, and EWS Managed API 1.1.

    Using the code below, if I omit the Folder.Bind, it creates the appointments perfectly in my User's Calendar, but nothing happens when I try to Bind to the PF (not even an exception).  I am using FindFolderByName Method I found on another support site, and if I put a breakpoint in on the Bind, during debug I can see the fid variable is assigned the long FolderID string.  Trying to manually assign that string to the FolderId fid returns an "Id is Malformed" exception.  I receive no exception when using the value returned by FindFolder.  Also the account I am authenticating with has owner rights on the public Calendar.

     

     

     protected void btn_CreateCalendar_Click(object sender, EventArgs e)
     {
    
     // Create Test Calendar Entry based on Entry Date Field
     ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
     service.Credentials = new WebCredentials("**************", "************");
     ServicePointManager.ServerCertificateValidationCallback = CertificateValidationCallBack;
    
     service.Url = new Uri("https://*********/EWS/Exchange.asmx");
    
     string fulldate = date_EntryDate.Text + " 09:00:00 AM";
     string PublicCalendar = "z-Test Docket Calendar";
     FolderId fid = FindFolderByName(service, PublicCalendar);
     // FolderId ffid = "AQEuAAADGkRzkKpmEc2byACqAC/EwgMA4FTx1Hmdm0K1uVD5sGiBIwAhG4hmCAAAAA==";
     CalendarFolder.Bind(service, fid);
     
    
     Appointment appointment = new Appointment(service);
     appointment.Subject = "" + lbl_DetailClient.Text + "-" + lbl_DetailMatter.Text + "";
     appointment.Body = "" + lbl_DetailMdesc.Text + "";
     appointment.Start = DateTime.Parse(fulldate);
     appointment.End = appointment.Start.AddHours(1);
    
     appointment.Save(SendInvitationsMode.SendToNone);
    
     Page.Response.Redirect(HttpContext.Current.Request.Url.ToString(), true); // reloads page when done
    
    
     }
    
     private static bool CertificateValidationCallBack(
     object sender,
     System.Security.Cryptography.X509Certificates.X509Certificate certificate,
     System.Security.Cryptography.X509Certificates.X509Chain chain,
     System.Net.Security.SslPolicyErrors sslPolicyErrors)
     {
     // If the certificate is a valid, signed certificate, return true.
     if (sslPolicyErrors == System.Net.Security.SslPolicyErrors.None)
     {
     return true;
     }
    
     // If there are errors in the certificate chain, look at each error to determine the cause.
     if ((sslPolicyErrors & System.Net.Security.SslPolicyErrors.RemoteCertificateChainErrors) != 0)
     {
     if (chain != null && chain.ChainStatus != null)
     {
     foreach (System.Security.Cryptography.X509Certificates.X509ChainStatus status in chain.ChainStatus)
     {
     if ((certificate.Subject == certificate.Issuer) &&
     (status.Status == System.Security.Cryptography.X509Certificates.X509ChainStatusFlags.UntrustedRoot))
     {
     // Self-signed certificates with an untrusted root are valid. 
     continue;
     }
     else
     {
     if (status.Status != System.Security.Cryptography.X509Certificates.X509ChainStatusFlags.NoError)
     {
     // If there are any other errors in the certificate chain, the certificate is invalid,
     // so the method returns false.
     return false;
     }
     }
     }
     }
    
     // When processing reaches this line, the only errors in the certificate chain are 
     // untrusted root errors for self-signed certificates. These certificates are valid
     // for default Exchange server installations, so return true.
     return true;
     }
     else
     {
     // In all other cases, return false.
     return false;
     }
     }
    
    
     public RemoteCertificateValidationCallback CertificateValidationCallback { get; set; }
    
     public FolderId FindFolderByName(ExchangeService service, string folderName)
     {
     FindFoldersResults findResults = service.FindFolders(WellKnownFolderName.PublicFoldersRoot, new FolderView(int.MaxValue));
    
     foreach (Folder folder in findResults)
     {
     if (folder.DisplayName == folderName)
     {
     return folder.Id;
     }
     }
    
     return null;
     }
     }
    

     

    I've tried for a few days to scour over support forums, but I cannot figure out what I am missing here.  Public Folder operations (especially Calendar) pages seems to be scarce.  Any help would be appreciated.

     

    Thank You,

    Jack

     

    UPDATE to Add:  The Authenticated user used to bind to ExchangeService also has send-as permissions on the public folder, and it is also set to mail-enable. (Not sure if that makes a difference, just trying to eliminate any security-related restrictions).



    Tuesday, May 3, 2011 5:42 PM

Answers

  • In your appointmet.save() method your not specifiying the FolderID of the Public folder you want to save it in this means it will save the appointment into the folder of the default calendar folder of the creating account the Calendar.Bind doesn't affect this default operation it just Binds to a seperate calendar folder object. So just adjust your code to include the FolderID in the save method.

    appointment.Save(CalendarFolder.Id,SendInvitationsMode.SendToNone);

     

    Cheers
    Glen  

    • Marked as answer by Mandel Katz Wednesday, May 4, 2011 3:05 PM
    Wednesday, May 4, 2011 11:27 AM

All replies

  • In your appointmet.save() method your not specifiying the FolderID of the Public folder you want to save it in this means it will save the appointment into the folder of the default calendar folder of the creating account the Calendar.Bind doesn't affect this default operation it just Binds to a seperate calendar folder object. So just adjust your code to include the FolderID in the save method.

    appointment.Save(CalendarFolder.Id,SendInvitationsMode.SendToNone);

     

    Cheers
    Glen  

    • Marked as answer by Mandel Katz Wednesday, May 4, 2011 3:05 PM
    Wednesday, May 4, 2011 11:27 AM
  • Thank you so much for your reply - that was absolutely it!  I knew I had to have missed something small.  Works perfectly now!

    Thank you,

    Jack

    Wednesday, May 4, 2011 3:05 PM