c# - using Outlook.AppointmentItem oAppointment for a specific user -
i've done research on , not been able find example exact problem, although there lot apologies if i've missed it.
i have code add appointment outlook calendar automatically, , send email recipient. want able add public calendar on generic username... code use adds user calendar logged in.
heres code on press of button:
private void button1_click(object sender, eventargs e) { string name = "test name"; datetime startdate = new datetime(2015, 4, 2); datetime enddate = new datetime(2015, 4, 2); outlook.application outlookapp = new outlook.application(); // creates new outlook app outlook.appointmentitem oappointment = (outlook.appointmentitem)outlookapp.createitem(outlook.olitemtype.olappointmentitem); // creates new appointment oappointment.subject = "enquiry changes made " + name + "'s enquiry"; // set subject oappointment.body = "this appointment body of appointment written"; // set body oappointment.location = "the location"; // set location oappointment.start = convert.todatetime(startdate); // set start date oappointment.end = convert.todatetime(enddate); // end date oappointment.reminderset = true; // set reminder oappointment.reminderminutesbeforestart = 15; // reminder time oappointment.importance = outlook.olimportance.olimportancehigh; // appointment importance oappointment.busystatus = outlook.olbusystatus.olbusy; oappointment.save(); outlook.mailitem mailitem = oappointment.forwardasvcal(); // email address send mailitem.to = "genericemail@provider.com"; // send mailitem.send(); }
thanks can give me.... , clarify, want able add appointment specific users calendar, not user logged onto machine.
here link extremely similar not have accepted answered: how set appointment other users on outlook?
using outlook exchange api solved issue:
//this initialize exchange web service object exchangeservice exchangeservice = new exchangeservice(exchangeversion.exchange2013); //setting service url try { exchangeservice.autodiscoverurl("emailaddress@domain.co.uk"); } catch (autodiscoverlocalexception ex) { //if auto discover url fails mannualy configure exchange service url exchangeservice.url = new uri("https://yourexchangename/ews/exchange.asmx"); console.writeline(ex.message); } exchangeservice.credentials = new webcredentials("username", "password", "domain"); //or exchangeservice.credentials = new networkcredential("username", "password", "domain"); appointment appointment = new appointment(exchangeservice); appointment.subject = "sample subject"; appointment.body = "sample body"; appointment.start = new datetime(2015, 4, 1, 8, 0, 0); appointment.end = appointment.start.addhours(9.5); // occurs every weeks on tuesday , thursday appointment.save();
this bit of code try 3 ways connect specific user account, in case generic user shared calendar kept. second part of code add appointment directly calendar.... hope helps people
Comments
Post a Comment