Click here to Skip to main content
15,887,394 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I want to create a Visual Studio 2022 program which makes it possible to create an appointment in someone else's Outlook calendar.

For example: if someone asks to create an appointment in someone else's Outlook calendar. I already made some code in which allows you to set your own appointments.
please help me ,
Quote:
not an event:
appointment.Id
"Appointment.id" Value cannot be null (Parameter 'itemId')


How to resolve this problem?

What I have tried:

C#
public async Task<bool> CreateAppointmentAsync()
{
    var spinId = Guid.NewGuid();
    StringBuilder apptBody = new StringBuilder();
    var httpClient = new System.Net.Http.HttpClient();
    System.Net.Http.HttpResponseMessage response;
    bool success = false;
    var username = _employee.Email;

    try
    {
        string ewsUrl = "https://outlook.office365.com/EWS/Exchange.asmx";
       
        ExchangeService servicex = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
        servicex.UseDefaultCredentials = true;
        servicex.Credentials = new WebCredentials("user@domain.com", "password");
        servicex.Url = new Uri(ewsUrl);
        servicex.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress,   "user@domain.com");

        Appointment appointment = new Appointment(servicex);
        // Set the properties on the appointment object to create the appointment.
        appointment.Subject = "Tennis lesson";
        appointment.Body = "Focus on backhand this week.";
        appointment.Start = DateTime.Now.AddDays(2);
        appointment.End = appointment.Start.AddHours(1);
        appointment.Location = "Tennis club";
        appointment.ReminderDueBy = DateTime.Now;
        appointment.Save(SendInvitationsMode.SendToNone);

        Item item = await Item.Bind(servicex, appointment.Id, new PropertySet(ItemSchema.Subject));

        success = true;
        MessageBox.Show("Sucessfully Event Created");
        Console.WriteLine("Subject of the retrieved appointment: " + item.Subject);
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
        return success;
    }
    finally
    {
        // Stop spinner
        Thread.Sleep(100);
        _eventAggregator.GetEvent<CloseControlEvent>().Publish(spinId.ToString());
    }
    return success;
}
Posted
Updated 4-Dec-23 21:26pm
v3
Comments
Richard MacCutchan 5-Dec-23 4:29am    
The other person would need to grant you permission to update their calendar. You need to check the Outlook documentation to see if this is possible.
Richard MacCutchan 5-Dec-23 5:50am    
You also need to correct the issue noted in the error message:
""Appointment.id" Value cannot be null (Parameter 'itemId')"

1 solution

You seem to be on the right track...

Please, take a look here: EWS - Create a meeting or appointment in other user calendar.[^]
You need to add a few lines of code and everything should start working.
 
Share this answer
 
v2
Comments
Andre Oosthuizen 5-Dec-23 14:36pm    
+5 Short and sweet!
Maciej Los 6-Dec-23 2:51am    
Thank you, Andre :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900