I'm trying to implement creating/updating appointments via C# code. I'm using dedicated exchange account and webdav to communicate. Updating appointment require saving this appointment to our tech-user mailbox.
Is there any other option to create and update appointments? Right now I'm struggling limits in quantity of calendar appointment on single mailbox.
I'm sure there should be other option but I can not see it.
Looking to see if anyone else has any suggestions or solutions to this issue.
Thanks
Creating an appointment...
//Give values to Subject,body,....
_service is the Exchange service object.
Appointment app = new Appointment(_service);
app.Subject = subject;
app.Body = body;
app.Start = startTime;
app.End = endTime;
app.Location = location;
DayOfTheWeek[] days = new DayOfTheWeek[] { DayOfTheWeek.Saturday };
app.Recurrence = new Recurrence.WeeklyPattern(app.Start.Date, 1, days);
app.Recurrence.StartDate = app.Start.Date;
app.Recurrence.NumberOfOccurrences = 3;
app.Save();
If you need further information please ask...
Related
I'm developing an Office VSTO add-in in C# which looks up calendar appointments in Outlook, and reads/writes some data in them.
Recently, one of the clients had issues with the add-in, namely they can't read/write the calendar appointment, and it throws an exception :
The operation failed.
There's not much info from the exception log, but I suspect they have synchronization problems with Exchange.
I asked the client, and they said, that they also have a random popup in Outlook as well, which sometimes happens when there's a mishap while syncing with Exchange. I told them to 'repair' the Outlook data files, but that didn't fix the problem.
The outlook items are basically looked up based on their Outlook EntryIDs OR a Subject (the subjects are unique, and for the sake of simplicity I translated the code a little bit)
...main alghorythm...
Outlook.AppointmentItem calAppointment = null;
calAppointment = SearchforCalendarMatch(EntryID, Subject); //we try to find either by EntryID or by Subject
if (calAppointment != null)
{
calAppointment.Start = StartDate;
calAppointment.End = FinishDate;
calAppointment.Body = Notes;
calAppointment.Save(); //we're changing the found calendar appointment here
}
...
public Outlook.AppointmentItem SearchforCalendarMatch(String EntryID, String Subject)
{
Outlook.NameSpace ns = null;
Outlook.MAPIFolder calendarFolder = null;
Outlook.Items calendarFolderItems = null;
Outlook.Items filteredcalendarFolderItems = null;
Outlook.AppointmentItem calAppointment = null;
Outlook.Application OutlookApp = new Outlook.Application();
outlookversion = OutlookApp.Version;
ns = OutlookApp.Session;
//Try to find the calendar appointment by the EntryID
dynamic OutlookItem = ns.GetItemFromID(t.Text28);
if (OutlookItem != null)
{
if (OutlookItem is Outlook.AppointmentItem)
{
Outlook.AppointmentItem foundItem = (Outlook.AppointmentItem)OutlookItem;
return foundItem;
}
}
//If the EntryID was missing, we try to find the calendar appointment by the Subject.
//(original code is very long, and there are multiple things here, but let's just assume that 100% sure that the subject is unique, so it will find it)
String SubjectMatch = "[Subject] = '" + Subject + "'";
filteredcalendarFolderItems = calendarFolderItems.Restrict(SubjectMatch);
for (int i = 1; i <= filteredcalendarFolderItems.Count; i++)
{
//appointment has to be one of these
calAppointment = (Microsoft.Office.Interop.Outlook.AppointmentItem)filteredcalendarFolderItems[i];
if (!calAppointment.IsConflict) //conflict check here, not sure if it helps at all
{
return calAppointment; //this is not the complete code, but this is the basic idea of it.
}
}
}
Any ideas how I could make the application recognize these failed Exchange syncs, and handle them differently?
I would still like to sync in these cases, if it's possible... (change the 'local data' in Outlook, then let Outlook handle everything from that on)
You need to release underlying COM objects instantly. Use System.Runtime.InteropServices.Marshal.ReleaseComObject to release an Outlook object when you have finished using it. This is particularly important if your add-in attempts to enumerate more than 256 Outlook items in a collection that is stored on a Microsoft Exchange Server. If you do not release these objects in a timely manner, you can reach the limit imposed by Exchange on the maximum number of items opened at any one time. Then set a variable to Nothing in Visual Basic (null in C#) to release the reference to the object. Read more about that in the Systematically Releasing Objects article.
I am creating a windows application in C# for setting appointments in a shared calendar for my team. I am the owner of the calendar. I have written the code to set the appointment and set reminder time as 24 hrs before the meeting. But instead of sending reminder to attendee it is sending reminder to me. I am using Microsoft.Office.Interop.Outlook for this. Here is the code that I used:
Outlook.Application oApp = new Outlook.Application();
// Get the NameSpace and Logon information.
Outlook.NameSpace oNS = oApp.GetNamespace("mapi");
// Get the Calendar folder.
Outlook.Recipient rcip = oNS.CreateRecipient("abc#domain.com");
Outlook.MAPIFolder oSharedCal = oNS.GetSharedDefaultFolder(rcip, Outlook.OlDefaultFolders.olFolderCalendar);
Outlook.MAPIFolder oShiftCal = oSharedCal.Folders["Sample"];
// Get the Items (Appointments) collection from the Calendar folder.
Outlook.Items oItems = oSharedCal.Items;
Outlook.AppointmentItem oAppt = (Outlook.AppointmentItem)oItems.Add();
// Set Appointment properties.
oAppt.Subject = Subject;
oAppt.Start = start;
oAppt.End = end;
oAppt.RequiredAttendees = email;
oAppt.ReminderMinutesBeforeStart = 24 * 60;
oAppt.ReminderSet = true;
oAppt.BusyStatus = Outlook.OlBusyStatus.olFree;
//Show the item to pause.
oAppt.Save();
oAppt.Send();
Can anyone help me with this?
Reminders cannot be set for attendees, they are for your copy of the appointment in the calendar you create it in. Attendees can set a reminder for themselves when the accept the meeting request.
I'm trying to implement PayPal subscriptions system with following features:
1st month of service on the application would be completely free after which user will pay monthly amount.
I have written the following code like below:
BillingPeriodType periodType = BillingPeriodType.MONTH;
switch (subs)
{
case("Month"):
periodType = BillingPeriodType.MONTH;
break;
case("Year"):
periodType = BillingPeriodType.YEAR;
break;
}
BasicAmountType paymentAmount = new BasicAmountType((CurrencyCodeType)EnumUtils.GetValue("USD", typeof(CurrencyCodeType)), subType.Price);
BillingPeriodType period = periodType;
BillingPeriodDetailsType paymentPeriod = new BillingPeriodDetailsType(period, 1, paymentAmount);
ScheduleDetailsType scheduleDetails = new ScheduleDetailsType();
/*Free trial period of 1 month for monthly sub*/
if (periodType == BillingPeriodType.MONTH)
{
scheduleDetails.TrialPeriod = new BillingPeriodDetailsType(BillingPeriodType.MONTH,1, new BasicAmountType((CurrencyCodeType)EnumUtils.GetValue("USD", typeof(CurrencyCodeType)), "0.01"));
scheduleDetails.TrialPeriod.TotalBillingCycles = 1;
}
else if (periodType == BillingPeriodType.YEAR)
{
scheduleDetails.TrialPeriod = new BillingPeriodDetailsType(BillingPeriodType.YEAR, 1, new BasicAmountType((CurrencyCodeType)EnumUtils.GetValue("USD", typeof(CurrencyCodeType)), "0.01"));
}
scheduleDetails.Description = "//Some description"
scheduleDetails.PaymentPeriod = paymentPeriod;
createRPProfileRequest.CreateRecurringPaymentsProfileRequestDetails.ScheduleDetails = scheduleDetails;
CreateRecurringPaymentsProfileReq createRPProfileReq = new CreateRecurringPaymentsProfileReq();
createRPProfileReq.CreateRecurringPaymentsProfileRequest = createRPProfileRequest;
This raises to me a huge security concern...
So let's suppose user subscribes for monthly subscription and get 1 month for free...
This way, nothing stops the user to cancel the subscription the last day and then to re-subscribe once again and re-use the 1 month trial period for free...
Currently of the users's information on PayPal I only store ProfileID information into the DB....
Is there any efficient way to see if the user has used free trial period on my website?
Also another security concern to me is that user can simply re-register with new account and subscribe once again under completely different ProfileID
How would you guys solve this?
I just hope I don't misunderstood your question:
Why don't you link the users PayPal e-mail address to the registered account? In this case the user has to use a different paypal account, so it's much easier to avoid people like this.
And at the users registration, the users should already provide his billing informations. Including his PayPal e-mail address.
Let's say I log in to the OS with administrator account and have permissions to set appointments to other users, without sending a mail.
How can I do it in the code?
I could only find examples working with AppontmentItem and set an appointment to the local machine's outlook. How can I do it for external users?
Many thanks in advance!
private static void AddAppointment()
{
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 = "Enquiry Changes made to john 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 = DateTime.Now.AddHours(2);
oAppointment.End = DateTime.Now.AddHours(3);
oAppointment.ReminderSet = true; // Set the 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();
}
Use Namespace.GetSharedDefaultFolder() to open other user's Calendar folder, then create an appointment using MAPIFolder.Items.Add.
Having created an outlook appointment doing something like this;
Microsoft.Office.Interop.Outlook.Application app = null;
Microsoft.Office.Interop.Outlook.AppointmentItem appt = null;
app = new Microsoft.Office.Interop.Outlook.Application();
appt = (Microsoft.Office.Interop.Outlook.AppointmentItem)app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olAppointmentItem);
appt.Subject = sub;
appt.Body = body;
appt.Location = Loc;
appt.Recipients.Add(email);
appt.Save();
appt.Send();
Outlook.MailItem mailItem = appt.ForwardAsVcal();
mailItem.To = email;
mailItem.Body = body;
mailItem.Send();
Looking for pointers, as I'm having difficulty finding a definitive answer via Google.
How do I then (at a later date..) retrieve this appointment again from one or more outlook accounts and update some details?
Or is it possible to release a new appointment that will overwrite the existing one?
If you are always accessing the appointment from the same mailbox, store the value of the AppointmentItem.EntryID property and reopen it at a later point using Namespace.GetItemfromID.
If you need to access the appointment from multiple mailboxes, read the value of the AppointmentItem.GlobalAppointmentID. Unfortunately Outlook Object Model would not let you search on a binary property (MAPIFolder.Items.Find). You would need to either drop down to the Extended MAPI level (C++ or Delphi) or use Redemption - see
http://social.msdn.microsoft.com/Forums/en-US/outlookdev/thread/63ea7bda-9767-4145-8ced-78e1095a49f8/