Hi,
Actually i want import outlook calender to my asp.net web application(CRM).
I don't have any idea how it is implemented. But someone tell me about exchange server.Can we do this using asp.net integration with exchange server like EWS.
class Program{
static void Main(string[] args)
{
ExchangeHelper exchangeHelper = new ExchangeHelper();
exchangeHelper.RetrieveAppointments("test.user100@emailHostDOTcom", DateTime.Now, DateTime.Now.AddHours(2));
}
}
public class ExchangeHelper
{
ExchangeService exchangeService;
public ExchangeHelper()
{
//Instantiate a new ExchangeService object
exchangeService = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
//Set the exchange WebService URL
exchangeService.Url = new Uri("https://mail.bhspecialty.com/EWS/exchange.asmx");
//Set the credentials of the service to the credentials
//that are associated with the impersonating account.
exchangeService.Credentials = new WebCredentials("bhsi/apache",
"Berksi2013",
"mail.bhspecialty.com"
);
}
public void RetrieveAppointments(string mailBox, DateTime startDate, DateTime endDate)
{
//Set the ImpersonatedUserId property of the ExchangeService object to identify the impersonated user (target account).
//This example uses the user's SMTP email address.
exchangeService.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, mailBox);
//bind to the calendar folder of mailBox and load all its first class properties
CalendarFolder folder = CalendarFolder.Bind(exchangeService, WellKnownFolderName.Calendar);
//Represents a date range view of appointments in calendar folder search operations
//If the CalendarView element is specified the Web service returns a list of single calendar items
//and occurrences of recurring calendar items within the range specified by StartDate and EndDate
CalendarView view = new CalendarView(startDate, endDate);
//search for appointments matching range specified in calendar view
FindItemsResults<Appointment> results = folder.FindAppointments(view);
//print results
foreach (Appointment appointment in results)
{
//find appointments will only give basic properties.
//in order to get more properties (such as BODY), we need to call call EWS again
Appointment appointmentDetailed = Appointment.Bind(exchangeService, appointment.Id, new PropertySet(BasePropertySet.FirstClassProperties) { RequestedBodyType = BodyType.Text });
Console.WriteLine("Appointment ID: " + appointment.Id);
Console.WriteLine("Subject: " + appointment.Subject);
Console.WriteLine("Start Time: " + appointment.Start.ToString("M/d/yyyy h:mm tt") + appointment.TimeZone);
Console.WriteLine("End Time: " + appointment.End.ToString("M/d/yyyy h:mm tt") + appointment.TimeZone);
if (!string.IsNullOrEmpty(appointmentDetailed.Body.Text))
Console.WriteLine("Body " + appointmentDetailed.Body.Text.Trim());
Console.WriteLine("Required Attendees");
foreach (Attendee attendee in appointmentDetailed.RequiredAttendees)
{
Console.WriteLine(" " + attendee.Address);
}
Console.WriteLine("Optional Attendees");
foreach (Attendee attendee in appointmentDetailed.OptionalAttendees)
{
Console.WriteLine(" " + attendee.Address);
}
Console.WriteLine();
}
//Set it back to null so that any actions that will be taken using the exchange service
//applies to impersonating account (i.e.account used in network credentials)
exchangeService.ImpersonatedUserId = null;
}
}