Exchange Web服务FolderId用于由用户创建的文件夹

时间:2016-10-03 13:03:31

标签: c# exchangewebservices

我在Exchange邮箱中有一个文件夹,它是root的子项,由用户创建。

如何使用EWS托管API找到此类文件夹?

我尝试使用深度遍历,但我找不到该文件夹​​。

先谢谢

编辑:以下是我用来获取用户创建的文件夹的代码

ExchangeService server = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
server.UseDefaultCredentials = true;
string configUrl = @"https://yourServerAddress.asmx";
server.Url = new Uri(configUrl);
//SetView
FolderView view = new FolderView(100);
view.PropertySet = new PropertySet(BasePropertySet.IdOnly);
view.PropertySet.Add(FolderSchema.DisplayName);
view.Traversal = FolderTraversal.Deep;
FindFoldersResults findFolderResults = server.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);
}

2 个答案:

答案 0 :(得分:0)

您应该在问题中包含您使用的代码,因为您可能只有错误。我所做的是使用一个函数从字符串路径中找到该文件夹​​然后你可以像GetFolderFromPath(service,“mailbox@domain.com”,“\\ folder1 \ Folder2”)那样调用它,例如

        internal static Folder GetFolderFromPath(ExchangeService service,String MailboxName,String FolderPath)
    {
        FolderId folderid = new  FolderId(WellKnownFolderName.MsgFolderRoot,MailboxName);   
        Folder tfTargetFolder = Folder.Bind(service,folderid);
        PropertySet psPropset = new PropertySet(BasePropertySet.FirstClassProperties);
        String[] fldArray = FolderPath.Split('\\'); 
        for (Int32 lint = 1; lint < fldArray.Length; lint++) { 
            FolderView fvFolderView = new FolderView(1);
            fvFolderView.PropertySet = psPropset;
            SearchFilter  SfSearchFilter = new SearchFilter.IsEqualTo(FolderSchema.DisplayName,fldArray[lint]); 
            FindFoldersResults findFolderResults = service.FindFolders(tfTargetFolder.Id,SfSearchFilter,fvFolderView); 
            if (findFolderResults.TotalCount > 0){ 
            foreach(Folder folder in findFolderResults.Folders){ 
                tfTargetFolder = folder;                
                } 
            } 
            else{ 
                tfTargetFolder = null;  
                break;  
            }     
        }
        if (tfTargetFolder != null)
        {
            return tfTargetFolder;
        }
        else
        {
            throw new Exception("Folder Not found");
        }
    }

答案 1 :(得分:0)

显然,您的代码是正确的,但它不会让您访问更严格的交换。我遇到了同样的问题,只修复了这些问题。

  

实际上MS忽略了UseDefaultCredentials = true;

这可能是您未登录Exchange服务器的原因。有关详细信息,请参阅MS文档here

使用此方法

 MSEWS.ExchangeService exchange = new MSEWS.ExchangeService(MSEWS.ExchangeVersion.Exchange2007_SP1);
// userid , password and your network domain
exchange.Credentials = new MSEWS.WebCredentials(userName, password, domain);

exchange.AutodiscoverUrl("tushar.kapoor@bollywood.com");