简体   繁体   中英

Get appointment from Office365 in C#.Net

Basically, My Knowledge level in Office 365 at Beginning level.

I am trying to pull the appointment from Office 365 through .Net Office 365 API call and show it in Windows Application Grid.

I am using code(below) to pull the appointments; I have collected the code from web...

I have succeeded till authentication part. I can view the authenticate success message and Office 365 calendar properties like FromTime , Location etc. But I am not able to receive the data. It returns System.Nullable DateTime Exception .

namespace GetCal
{
    public class CalendarAPISample
    {
        const string ExchangeResourceId = "https://outlook.office365.com";
        const string ExchangeServiceRoot = "https://outlook.office365.com/ews/odata";

        public static async Task<IOrderedEnumerable<IEvent>> GetCalendarEvents()
        {
            var client = await EnsureClientCreated();
            string fromdate = "01/01/2014";
            DateTime datet = Convert.ToDateTime(fromdate);

            // Obtain calendar event data
            var eventsResults = await(from i in client.Me.Events
                                       where i.End >= datet //DateTimeOffset.UtcNow
                                  select i).Take(10).ExecuteAsync();

            var events = eventsResults.CurrentPage.OrderBy(e => e.Start);
            //return events.ToList().ConvertAll(new Converter(ent => ent));
            return events;
        }

        private static async Task<ExchangeClient> EnsureClientCreated()
        {
            Authenticator authenticator = new Authenticator();
            var  authInfo = await authenticator.AuthenticateAsync(ExchangeResourceId);

            return new ExchangeClient(new Uri(ExchangeServiceRoot), authInfo.GetAccessToken);
        }

        public static async Task SignOut()
        {
            await new Authenticator().LogoutAsync();
        }

        public CalendarAPISample()
        {
            // TODO: Complete member initialization
            try
            {
                // call the authenticator
                var x = GetCalendarEvents();              

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
}

In the EVENTS objects contains IEnumerable datatype values. I want convert IEnumerable to DataTable .

Have you tried making your DateTime nullable?

Put a question mark after DateTime...

DateTime? datet = Convert.ToDateTime(fromdate);

http://www.dotnetperls.com/nullable-datetime

You can also use a program such as Fiddler to investigate the web traffic and see what (if anything) is coming back in the response.

http://www.telerik.com/download/fiddler

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM