Click here to Skip to main content
15,847,077 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 ,
not an event:
"" Value cannot be null (Parameter 'itemId')

How to resolve this problem?

What I have tried:

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;

        string ewsUrl = "";
        ExchangeService servicex = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
        servicex.UseDefaultCredentials = true;
        servicex.Credentials = new WebCredentials("", "password");
        servicex.Url = new Uri(ewsUrl);
        servicex.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress,   "");

        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;

        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)
        return success;
        // Stop spinner
    return success;
Updated 4-Dec-23 22:26pm
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:
""" 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
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