I have created Following function to set Outlook appointment. It's work fine while running in localhost with visual Studio Editor.
But when I upload publish files on server its not working.
Do I need to set anything in server for Outlook or need to include any additional dll/files?
Any help will be appreciated. Pls let me know, if need more information.
public void OutLookReminder(string DateTimeVal)
{
Outlook.Application outlookApp = new Outlook.Application(); // creates new outlook app
Outlook.AppointmentItem oAppointment = (Outlook.AppointmentItem)outlookApp.CreateItem(Outlook.OlItemType.olAppointmentItem); // creates a new appointment
oAppointment.Subject = "........Subject"; // set the subject
oAppointment.Body = "--------Body"; // set the body
oAppointment.Location = "-------Location"; // set the location
oAppointment.Start = DateTime.ParseExact(DateTimeVal, "dd/MM/yyyy H:mm",null); // Set the start date
oAppointment.End = DateTime.ParseExact(DateTimeVal, "dd/MM/yyyy H:mm", null); // End date
oAppointment.ReminderSet = true; // Set the reminder
oAppointment.ReminderMinutesBeforeStart = 15; // reminder time
oAppointment.Importance = Outlook.OlImportance.olImportanceHigh; // appointment importance
oAppointment.BusyStatus = Outlook.OlBusyStatus.olBusy;
// save the appointment
oAppointment.Save();
}
Do you mean you are running this under a service (such as IIS)? You cannot do that.
Where is the appointment supposed to be created? Current user who is using your code in a browser (then your code needs to run locally in JavaScript)?
Related
I am trying to save an Outllok meeting ics file as an Outlook appointment ics but when i use do SaveAs to a folder location, it is saving as a meeting.
I have the following code but I can not seem to locate the issue. When I use .Display it shows as an appointment but .SaveAs is saving back as a meeting with recipients.
Any help is much appreciated
Outlook.Application App = new Outlook.Application();
string FPath = #"C:\\Documents\TestMeeting.ics"
var item = App.Session.OpenSharedItem(FPath) as Outlook.MeetingItem;
var AppointmentItem = item.GetAsssociatedAppointment(false);
AppointmentItem.MeetingStatus = Outlook.OlMeetingStatus.olNonMeeting;
AppointmentItem.Display(true);
AppointmentItem.SaveAs(#"C:\\Documents\TestAppointment1.ics",Outlook.OlSaveAsType.olIcal);
Use the Save method to save the just opened meeting into your calendar:
string FPath = #"C:\\Documents\TestMeeting.ics"
var item = App.Session.OpenSharedItem(FPath) as Outlook.MeetingItem;
item.Save();
// only after that you can try reprieving the associated appointment
var AppointmentItem = item.GetAsssociatedAppointment(false);
Also I'd recommend creating a new appointment item from scratch and then saving it to the disk.
Thanks Eugene. I managed to get this working by creating a new appointment and using .BodyFormat and .RTFBody of the associated appointment. I have included the full code below for anyone in the future and marked your answer as correct. Apologies but at present I don't have enough rep to upvote otherwise I would. Many thanks
Outlook.Application App = new Outlook.Application();
string FPath = #"C:\\Documents\TestMeeting.ics"
var item = App.Session.OpenSharedItem(FPath) as Outlook.MeetingItem;
var AppointmentItem = item.GetAsssociatedAppointment(false);
Outlook.AppointmentItem ap1 = (Outlook.AppointmentItem)App.CreateItem(Outlook.OlItemType.olAppointmentItem);
ap1.Start = AppointmentItem.Start;
ap1.Subject = AppointmentItem.Subject;
ap1.BodyFormat = AppointmentItem.BodyFormat;
ap1.RTFBody = AppointmentItem.RTFBody;
ap1.Location = AppointmentItem.Location;
ap1.SaveAs(#"C:\\Documents\TestAppointment1.ics",Outlook.OlSaveAsType.olIcal);
I'm trying to create a program that allows me to add multiple appointments/events to multiple users (without using a shared calendar).
The problem arrives when I try to impersonate someone (I'm admin so I think that I don’t have "rights" problems), I get an error System.NullReferenceException : 'Object reference not set to an instance of an object.' when the appoinment is saved (not when the impersonation is created, I don't understand why)
I don’t know what object I have to instantiate
If I don’t impersonate, the code works. The appointment is created
try
{
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.UseDefaultCredentials = true;
service.Credentials = new WebCredentials(userEmail, userPassword);
service.Url = new Uri("https://outlook.office365.com/ews/exchange.asmx");
service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, destEmail);
//service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, myEmail);
Appointment appointment = new Appointment(service);
// Set the properties on the appointment object to create the appointment.
appointment.Subject = subject;
appointment.Body = "Test Event";
appointment.Start = DateTime.Now.AddDays(2);
appointment.End = appointment.Start.AddHours(1);
appointment.Location = "Here";
appointment.ReminderDueBy = DateTime.Now;
// Save the appointment to your calendar.
appointment.Save();
// Verify that the appointment was created by using the appointment's item ID.
Item item = Item.Bind(service, appointment.Id, new PropertySet(ItemSchema.Subject));
Console.WriteLine("Appoinement created");
}
catch (Exception ex)
{
Console.WriteLine("The following error occurred: " + ex.Message);
}
Error when I try to save the appoinement
-------------------- Update 02.07.2021
Thanks for the remarks.
I removed service.UseDefaultCredentials = true, that's dummy if a set new credentials in the next line.
The Appointment class is the default Microsoft.Exchange.WebServices.Data.Appointment, i didnt change anything there.
IT WAS a security/rights problem. Eventhough I'm admin, admins doesn't have Impersonnation ritghs by default.
The thing is that I added to myself the impersonation rights needed, and it worked. Thanks
It worked for a while. It stopped working without reason, i didnt change anything.
So I waited a few hours, tryed again, still didnt work and then I re-added the rights, and it works again.
Thanks you very much for the comments/hints
We're using EWS to integrate our CRM with Exchange Online 2010SP2. One of the tasks: provide one calendar for Sales persons with the next rule: every Sales can see all appointments in Scheduler, but can open and see details (body) only his/her own appointment. Appointment are being placed by CRM in response of certain business events. We tried to use impersonate and Sensitivity.Private property. Appointment is being placed with impersonated user name, but it can't be opened by that user neither through OWA nor via Outlook. So it's placed as private appointment of 'master' user (user who created shared calendar and his credentials is used for service connection), he can open it in Outlook or OWA. EWSEditor shows appointment's LastModifiedUser - correct impersonated username (not master's). In Fiddler we can see 'success' Response on appointment placement request (under impersonated user). In OutlookSpy, we can see that appointments PR_SENDER_NAME_W, PR_SENT_REPRESENTING_NAME_W properties shows 'master's' username. We stuck.
Impersonated user has 'owner' rights upon that shared calendar.
If Impersonating doesn't resolve this issue, can Delegate technique do that?
Thanks in advance for any help.
static void Main(string[] args)
{
ExchangeService services = new
ExchangeService(ExchangeVersion.Exchange2010_SP2);
services.Credentials = new WebCredentials("master#exchserver.com",
"MasterPwd");
services.Url = new Uri("https://someserver.com/ews/exchange.asmx");
FolderId rfRootFolderid = new FolderId(WellKnownFolderName.Calendar);
FolderView fvFolderView = new FolderView(100);
DateTime startDate = DateTime.Now.AddDays(1);
DateTime endDate;
string SalesCalendarId = "AAMkADVlMGVjZWVkLT....AADo8XAAA=";
CalendarFolder folder = CalendarFolder.Bind(services, new
FolderId(SalesCalendarId));
TimeSpan ts = new TimeSpan(10, 00, 0);
startDate = startDate.Date + ts;
endDate = startDate.AddMinutes(60);
services.HttpHeaders.Add("X-AnchorMailbox","impersonateduser#exchserver.com");
appointment.Subject = "from Test";
appointment.Body = "Test";
appointment.Start = startDate;
appointment.End = appointment.Start.AddMinutes(30);
appointment.ReminderDueBy = appointment.Start.AddHours(1);
appointment.Sensitivity = Sensitivity.Private;
ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "impersonateduser#exchserver.com");
appointment.Save(SalesCalendarId, SendInvitationsMode.SendToNone);
}
You could use impersonated user to obtain ‘owner’ permissions.
Please include the code below before services.Credentials = new WebCredentials("master#exchserver.com", "MasterPwd")
services.PreAuthenticate = true;
you need to make sure that we have required permissions for EWS Impersonation as per the article mentioned below:
Configuring Exchange Impersonation in Exchange 2010
Using Exchange Impersonation in Exchange 2010
You could reference the following link:
Get all calendar events for a specific user
I am creating simple app for appointments scheduling and I want to implement ability for me to create appointments for my users.
I managed to create,update and delete my calendar on Exchange Server, and I somewhat managed to create appointments adding my colleagues as RequiredAttendees like so:
//service variable is being created using my credidentals
Appointment meeting = new Appointment(service);
meeting.Subject = "Some subject ";
meeting.Body = "Some body.";
meeting.Start = DateTime.Now;
meeting.End = meeting.Start.AddHours(4);
meeting.Location = "Some Location";
meeting.RequiredAttendees.Add("myCollegue#mail.com");
meeting.ReminderMinutesBeforeStart = 60;
meeting.Save(new FolderId(WellKnownFolderName.Calendar,
"myCollegue#mail.com"),
SendInvitationsMode.SendToAllAndSaveCopy);
But it is just setting him as required attendee. Next thing is I tried using impersonation, but I can't access hosting server to set myself as master and others to have to share calendar with me (due to permissions and stuff) so I had to scrape that as well. Also, he set me up to be his publishing author on his calendar.
Is there something I am missing, or can't seem to find on MSDN sites?
EDIT: I am able to create appointment in his calendar in outlok.
If anyone comes across same issues as I did in here please follow these steps:
Make sure that person for which you are creating appointment sets you up (on exchange server or in outlok as "Editing author" with all permissions.
After that you can create appointments for him (verify this by going to your outlok and creating some test appointments).
This code works for me:
Folder inboxFolder = Folder.Bind(service, new FolderId(WellKnownFolderName.Calendar, "your.colleague#company.com"));
Appointment appointmentOther = new Appointment(service);
appointmentOther.Subject = "Test 2";
appointmentOther.Body = "Body text";
appointmentOther.Start = DateTime.Now;
appointmentOther.End = DateTime.Today.AddHours(16);
appointmentOther.Location = "My Office";
appointmentOther.IsReminderSet = true;
appointmentOther.ReminderMinutesBeforeStart = 30;
appointmentOther.Save(inboxFolder.Id,SendInvitationsMode.SendToNone);
Good luck :)
Can anyone answer this question as soon as possible.
Code for Asp .net application and outlook:
public void MyMessage()
{
Microsoft.Office.Interop.Outlook.Application outlookApp = new Microsoft.Office.Interop.Outlook.Application(); // creates new outlook app
Microsoft.Office.Interop.Outlook.AppointmentItem oAppointment = (Microsoft.Office.Interop.Outlook.AppointmentItem)outlookApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olAppointmentItem); // creates a new appointment
// Step 3 // Set appointment settings
oAppointment.Subject = "Enquiry Changes made to " + "Appointment Fixed " + "'s enquiry"; // set the subject
oAppointment.Body = "This is where the appointment body of the appointment is written"; // set the body
oAppointment.Location = "Nicks Desk!"; // set the location
oAppointment.Start = Convert.ToDateTime(DateTime.Now); // Set the start date
oAppointment.End = Convert.ToDateTime(DateTime.Now); // End date
oAppointment.ReminderSet = true; // Set the reminder
oAppointment.ReminderMinutesBeforeStart = 15; // reminder time
oAppointment.Importance = Microsoft.Office.Interop.Outlook.OlImportance.olImportanceHigh; // appointment importance
oAppointment.BusyStatus = Microsoft.Office.Interop.Outlook.OlBusyStatus.olBusy;
//Step 4 // save the appointment
oAppointment.Save();
// Step 5 - Check your outlook calender
//Appointment will now be added to your calender
//Step 6 // send the details in email
Microsoft.Office.Interop.Outlook.MailItem mailItem = oAppointment.ForwardAsVcal();
// email address to send to
mailItem.To = "railwaydummy#gmail.com";
// send
mailItem.Send();
}
I want code for if someone reject appointment in outlook then mail will send to user that your appointment rejected and it will reflect in asp application . Appointment rejected.
1.The recipient declines the invitation from Outlook Calendar - should trigger related rejection workflow in asp application
2.The recipient reschedules the invitation through ASP application without going through the Outlook Calendar for a different date or time - automatic reschedule in Outlook