zoukankan      html  css  js  c++  java
  • migarating calendatar data from shared exchange 2010 calendar to sharepoint 2013

           public static void AddAppointmentToSharepointWithClientObjectModule(DateTime s,DateTime e,string title,string desc)
            {
                string siteUrl = "https://intern.abc.net.cn/";
                ClientContext clientContext = new ClientContext(siteUrl);
                NetworkCredential Cred = new NetworkCredential("test", "abcdefg", "domain");
                clientContext.Credentials = Cred;
    
    
                //end authentication
                Microsoft.SharePoint.Client.List oList = clientContext.Web.Lists.GetByTitle("cal");
    
                ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
                ListItem oListItem = oList.AddItem(itemCreateInfo);
                oListItem["Title"] = title;
                oListItem["Description"] = "New Event created using SharePoint Object Model";
                //oListItem["Location"] = "First Floor";
                oListItem["EventDate"] = s;
                oListItem["EndDate"] = e;
                //oListItem["Category"] = "Business";
                //oListItem["fAllDayEvent"] = false;
                oListItem.Update();
    
                clientContext.ExecuteQuery();
    
            }
    
    
            public static void GetExchangePublicCalendar()
            {
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                ExData.ExchangeService service = new ExData.ExchangeService(ExData.ExchangeVersion.Exchange2010_SP2);
                service.Credentials = new NetworkCredential("test", "abcdefg", "domain");
                service.Url = new Uri("https://mail.abc.local/ews/Exchange.asmx");
                
                
                //service.Credentials = new NetworkCredential("test", "abcdefg", "temp");
                //service.Url = new Uri("https://cas.temp.local/ews/Exchange.asmx");
    
                var rootfolder = ExData.Folder.Bind(service, ExData.WellKnownFolderName.PublicFoldersRoot);
                rootfolder.Load();
                foreach (ExData.Folder folder in rootfolder.FindFolders(new ExData.FolderView(int.MaxValue)))
                {
                    if (!string.IsNullOrEmpty(folder.DisplayName))
                    {
                        Console.WriteLine(folder.DisplayName);
                        try
                        {
                            foreach (ExData.Folder f1 in folder.FindFolders(new ExData.FolderView(int.MaxValue)))
                            {
                                if (f1.DisplayName.ToLower() == "calender")
                                {
                                    Console.WriteLine("   ---------");
                                    sb.AppendLine("   ---------");
                                    var _cal = f1.Id;
                                    var _calendarView = new Microsoft.Exchange.WebServices.Data.CalendarView(System.DateTime.Now.AddYears(-6).AddYears(-1), System.DateTime.Now.Date.AddYears(-6).AddYears(1));
                                    foreach (Microsoft.Exchange.WebServices.Data.Appointment appointmentItem in service.FindAppointments(_cal, _calendarView))
                                    {
                                        AddAppointmentToSharepointWithClientObjectModule(appointmentItem.Start, appointmentItem.End,appointmentItem.Subject,"");
                                        Console.WriteLine(appointmentItem.Subject);
                                        sb.AppendLine(appointmentItem.Subject);
                                        Console.WriteLine(appointmentItem.Start);
                                        sb.AppendLine(appointmentItem.Start.ToString());
                                        Console.WriteLine(appointmentItem.End);
                                        sb.AppendLine(appointmentItem.End.ToString());
                                        //appointmentItem.Load();
                                        //Console.WriteLine(appointmentItem.Body);
    
                                    }
                                    Console.WriteLine("   ---------");
                                    sb.AppendLine("   ---------");
    
                                }
                                Console.WriteLine(" ++" + f1.DisplayName);
                                foreach (ExData.Folder f2 in f1.FindFolders(new ExData.FolderView(int.MaxValue)))
                                {
                                    Console.WriteLine("    ++" + f2.DisplayName);
                                    sb.AppendLine("    ++" + f2.DisplayName);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(" --" + ex.Message);
                            sb.AppendLine(" --" + ex.Message);
                        }
                    }
                }
                log(sb.ToString());
            }
    
            static void log(string str)
            { 
                System.IO.File.AppendAllText(@"c:\log.txt",str);
            }
  • 相关阅读:
    逆变电路技术研究!
    GOOGLE日历(管理自己的日常事务!)
    MATLAB使用的几个小问题(随笔记录下,用作以后参考!)
    ASP.NET截取字符串
    ASP.NET以及JS获取URL和IP地址
    Jvascript 做IE功能按钮,打开、另存为。属性、打印、收藏夹等js按钮
    C# winform 动态添加控件 以及 事件
    VS2008简体中文正式版序列号
    js 获取日期
    ASP.NET读取XML某节点所有数据返回DataTable实例
  • 原文地址:https://www.cnblogs.com/zyip/p/3096182.html
Copyright © 2011-2022 走看看