EWS:尝试查找唯一的文件夹ID

时间:2018-12-21 12:36:31

标签: c# visual-studio-2010 exchangewebservices

我尝试使用EWS API编写解决方案,以找到Outlook的唯一文件夹ID。由于某种原因,代码无法正常工作,我无法弄清楚问题出在哪里。我没有使用EWS API的经验。

namespace ClassLibrary1
{
public class Class1
{

    static void Main(string[] args)
    {



        // Set server binding

        ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
        service.UseDefaultCredentials = true;

        // Set Credentials
        service.Credentials = new WebCredentials("xxxxxxxxx", "xxxxxx");
        service.UseDefaultCredentials = true;

        // Set the URL 
        service.AutodiscoverUrl("xxxxx");

        // Set View

        FolderView view = new FolderView(100);
        view.PropertySet = new PropertySet(BasePropertySet.IdOnly);
        view.PropertySet.Add(FolderSchema.DisplayName);
        view.Traversal = FolderTraversal.Deep;
        FindFoldersResults findFolderResults = service.FindFolders(WellKnownFolderName.Root, view);

        // Find specific folder

        foreach (Folder f in findFolderResults)
        {

            // Show FolderId of the folder "test"
            if (f.DisplayName == "Test")
                Console.WriteLine(f.Id);
        }

    }
}

}

它说未处理的异常,autodsicover阻止了可能不安全的重定向(..)

1 个答案:

答案 0 :(得分:0)

发生错误时,它表示您需要使用回调来允许重定向。沿线的东西

service.AutodiscoverUrl("xxxxx", ValidateRedirectionUrlCallback);
...
private static bool ValidateRedirectionUrlCallback(string url)
{
    // Validate the URL and return true to allow the redirection or false to prevent it.
    return true; //allow redirections
}