最初由其他人编写的一些代码突然停止了它应该做的事情。
代码应该从其他帐户中查找共享日历并获取其中的事件,但不再查找此共享日历或任何共享日历。
我无权访问共享日历的帐户,但我尝试从其他帐户共享日历,但它也不会显示,但是在脚本使用的帐户中创建日历时,它显示正常。 登录帐户时可以看到共享日历。并且可以创建和看到事件。
我对交换知识有限,但我需要这个脚本才能工作。
我已经四处寻找已经回答过类似问题的问题,并尝试了一些解决方案,但到目前为止还没有任何解决方案或其他问题和/或缺乏知识。
我知道并没有改变这一点,并且该帐户的所有者声称我可以完全访问日历,并且没有任何改变。所以我不知道为什么会突然停止工作。
为澄清,没有错误。 try-catch不会触发,脚本会在页面中打印文件夹列表。 问题是该列表不包含网站上可见的共享日历。
const string EWSUrl = @"https://outlook.office365.com/ews/exchange.asmx";
const string EmailAdre = "myEmail";
const string EmailPass = "myPassword";
const string EmailDomi = "domi";
const string EmailCale = "targetAccount";
const int calFolderLimit = 200; // Limit on folder search
const int calMaxItemsReturned = 500; // Max limit cal fetch
const int calMonthLimit = 12; // How many months to fetch
const int calMonthBack = 1; // Update how many days back
// Tries to find one of this
const string calFolderName = "Ekonomi Årskalender";
const string calFolderID = "AQMkAGU5NTdjYTE5LTZiNWMtNDYzMi05MWQ4LWQ5MDcyMgA1YjMwMTYALgAAA5ukgsUdw+BFjn7iHZ02H3gBAM/bOclCwmFEsqKa2vRsw2EAAAIBWQAAAA==";
const string EWSUrl = @"https://outlook.office365.com/ews/exchange.asmx";
const string EmailAdre = "myEmail";
const string EmailPass = "myPassword";
const string EmailDomi = "domi";
const string EmailCale = "targetAccount";
const int calFolderLimit = 200; // Limit on folder search
const int calMaxItemsReturned = 500; // Max limit cal fetch
const int calMonthLimit = 12; // How many months to fetch
const int calMonthBack = 1; // Update how many days back
// Tries to find one of this
const string calFolderName = "Ekonomi Årskalender";
const string calFolderID = "AQMkAGU5NTdjYTE5LTZiNWMtNDYzMi05MWQ4LWQ5MDcyMgA1YjMwMTYALgAAA5ukgsUdw+BFjn7iHZ02H3gBAM/bOclCwmFEsqKa2vRsw2EAAAIBWQAAAA==";
protected string syncCalendar(HttpContext context)
{
string response = "";
try
{
// CONNECT TO EXCHANGE
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
service.Credentials = new WebCredentials(EmailAdre, EmailPass, EmailDomi);
service.TraceEnabled = true;
service.TraceFlags = TraceFlags.All;
service.EnableScpLookup = true;
service.AcceptGzipEncoding = true;
service.Url = new Uri(EWSUrl);
// Find Folder
FolderView folderView = new FolderView(calFolderLimit);
folderView.Traversal = FolderTraversal.Deep;
folderView.PropertySet = new PropertySet(FolderSchema.FolderClass, FolderSchema.DisplayName, FolderSchema.TotalCount, FolderSchema.ParentFolderId);
FindFoldersResults folders = service.FindFolders(new FolderId(WellKnownFolderName.Root), folderView);
foreach (var myFolder in folders.Folders)
{
if (myFolder is CalendarFolder && (myFolder.DisplayName == calFolderName || myFolder.Id.ToString() == calFolderID))
{
//Doing stuff with matched calendar folder
//Print name for debugging
response += "<div>" + myFolder.DisplayName + "</div>";
}
}
}
catch (Exception ex)
{
response += "[ERROR]<p>" + ex.Message + "<p/><p>" + ex.StackTrace + "</p>";
}
return response;
}
答案 0 :(得分:1)
你发布的这段代码没有与原作者交谈很有意义,很难确定为什么会这样做。让我们先来看看
const string calFolderID =&#34; AQMkAGU5NTdjYTE5LTZiNWMtNDYzMi05MWQ4LWQ5MDcyMgA1YjMwMTYALgAAA5ukgsUdw + BFjn7iHZ02H3gBAM / bOclCwmFEsqKa2vRsw2EAAAIBWQAAAA ==&#34 ;;
看起来你试图找到硬编码的文件夹的ews FolderId?这不是一个好主意,例如,如果邮箱从OnPrem迁移到Office365,则FolderId会有所不同,这会破坏代码(这是我的第一个猜测,如果你说它确实有效,它为什么不工作?第一名)。
但是,如果您已经拥有该文件夹的EWS FolderId,那么其余的代码都是redudant,您可以通过绑定到folderId完成同样的事情,例如
FolderId fldId = new FolderId("AQMkAGU5NTdjYTE5LTZiNWMtNDYzMi05MWQ4LWQ5MDcyMgA1YjMwMTYALgAAA5ukgsUdw+BFjn7iHZ02H3gBAM/bOclCwmFEsqKa2vRsw2EAAAIBWQAAAA==");
Folder myFolder = Folder.Bind(service, fldId);
但最有可能的是,你想要访问的FolderId可能已经改变,快速修复它的唯一方法就是打开目标邮箱,你要绑定的日历就是抓取新的folderId。您可以使用EWSEditor https://ewseditor.codeplex.com/来获取它,而无需编写任何代码。一旦你有快速修复工作,我建议你重写整个事情,以防止它在未来破坏。