问题描述
我在Exchange邮箱中有一个文件夹,该文件夹是根目录的子目录,由用户创建.
I have a folder in an Exchange mailbox that is a child of the root and is created by user.
如何使用EWS托管API找到这样的文件夹?
How do I find such a folder using EWS managed API?
我尝试使用深度遍历,但找不到该文件夹.
I tried using deep traversal, but I can't find the folder.
这是我用来获取用户创建的文件夹的代码:
Here is the code I am using to get the folder created by user:
ExchangeService server = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
server.UseDefaultCredentials = true;
string configUrl = @"https://yourServerAddress.asmx";
server.Url = new Uri(configUrl);
// set View
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);
}
}
推荐答案
您应该在问题中包括正在使用的代码,因为您可能只是其中的错误.我要做的是使用一个函数从字符串路径中查找文件夹,然后可以像GetFolderFromPath(service, "[email protected]", "\\\folder1\Folder2")
这样调用它,例如:
You should include the code you're using in your question as you probably just have bug in that. What I do is use a function to find the folder from a string path then you can just call that like GetFolderFromPath(service, "[email protected]", "\\\folder1\Folder2")
, e.g.:
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");
}
}
这篇关于用户创建的文件夹的Exchange Web服务FolderId的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!