How to catch specific exception when using Exchange Web Services(EWS) in c#
I am using EWS to create an appointment in the user's outlook. Here is my
code:
try
{
ExchangeService service = new
ExchangeService(ExchangeVersion.Exchange2010_SP2);
service.Credentials = new WebCredentials("Username", "Password");
service.AutodiscoverUrl("emailid@abc.com",
RedirectionUrlValidationCallback);
Appointment app = new Appointment(service);
app.Subject = subject;
app.Body = "Appointment generated from CRM Application";
app.Location = location;
app.Start = start;
app.End = end;
app.IsReminderSet = true;
app.ReminderMinutesBeforeStart = 15;
app.RequiredAttendees.Add(new Attendee("emailid@abc.com");
app.Save(SendInvitationsMode.SendToAllAndSaveCopy);
app.LegacyFreeBusyStatus = LegacyFreeBusyStatus.Busy;
}
catch(AutodiscoverLocalException autoExc)
{
}
catch (Exception gex)
{
}
static bool RedirectionUrlValidationCallback(String redirectionUrl)
{
bool redirectionValidated = false;
if (redirectionUrl.Equals(
"https://servername/autodiscover/autodiscover.xml"))
redirectionValidated = true;
return redirectionValidated;
}
The above code is able to create appointments in the outlook. But If in
case the password is incorrect then I want to catch specific
error('password incorrect') in the Exception in order to show the user
that Password is incorrect.
The Autodiscover is giving a generic exception for all kind of errors-
'The Autodiscover service couldn't be located.'
Could someone please help to find out how to catch a specific error in
AutodiscoverLocalException/General Exception ?
Thanks in Advance!
No comments:
Post a Comment