当前位置: 首页 > 编程语言 > C#

通过提供其PATH名称来搜索公用文件夹中的文件夹分享

时间:2023-04-10 12:58:58 C#

C#学习教程:通过提供路径名称在公共文件夹中搜索文件夹公共文件夹中的文件夹?您只能在EWS上的一级文件夹中搜索,因此:PublicFoldersRootsubjectAsectionBPARTC我会搜索“subjectA”文件夹,然后一旦我有了FolderId,我就会搜索“sectionB”文件夹,依此类推,直到找到我想要的需要。GetPublicFolderByPath方法采用路径“subjectAsectonBpartC”并将路径拆分为文件夹名称数组,然后递归查找每个文件夹。publicFolderGetPublicFolderByPath(ExchangeServiceservice,StringewsFolderPath){String[]folders=ewsFolderPath.Split('');文件夹parentFolderId=null;文件夹actualFolder=null;for(inti=0;i方法GetTopLevelFolder获取第一个文件夹“sectionA”,这是公用文件夹根目录的子项,即“WellKnownFolderName.PublicFoldersRoot”。私人文件夹GetTopLevelFolder(ExchangeService服务,字符串文件夹名称){FolderViewfolderView=newFolderView(int.MaxValue);FindFoldersResultsfindFolderResults=service.FindFolders(WellKnownFolderName.PublicFoldersRoot,folderView);foreach(FolderfolderinfindFolderResults(.ElefolderResults){folder.DisplayName,StringComparison.InvariantCultureIgnoreCase)){返回文件夹;}}thrownewException("找不到顶级文件夹:"+folderName);GetFolder方法采用父FolderId并在所有子文件夹中搜索与提供的名称匹配的项,然后返回您请求的子FolderId。私人文件夹GetFolder(ExchangeService服务,FolderIdParentFolderId,StringfolderName){FolderViewfolderView=newFolderView(int.MaxValue);FindFoldersResultsfindFolderResults=service.FindFolders(ParentFolderId,folderView);foreach(FolderfolderinfindFolderResults){if(folderName.Equals(folder.DisplayName,StringComparison.InvariantCultureIgnoreCase)){返回文件夹;}}thrownewException("找不到文件夹:"+folderName);}请注意,我使用的是Microsoft.Exchange.WebServices托管的APIdll,与https://yourexchangeserver/ews/services.wsdl类似。要从路径获取文件夹,请使用createService对象,然后写入:GetPublicFolderByPath(service,"subjectAsectionBpartC")如果这对您有帮助,请点赞:)这是基于@ono2012上面的答案的包装器,是C#学习教程:通过提供其PATH名称来搜索public文件夹中文件夹共享的所有内容。如果对大家有用,需要进一步了解C#学习教程,希望大家多多关注---usingSystem;使用System.DirectoryServices.AccountManagement使用System.Linq;使用System.Net;使用System.Net.Security;使用System.Security.Cryptography.X509Certificates;使用Microsoft.Exchange.WebServices.Data;namespaceEmailServices.Web.IntegrationTests{//http://msdn.microsoft.com/en-us/library/exchange/jj220499(v=exchg.80).aspx内部类MsExchangeServices{publicMsExchangeServices(){ServicePointManager.ServerCertificateValidationCallback=证书验证回调;m_exchangeService=newExchangeService{UseDefaultCredentials;//=true谁在运行这个测试?他们最好具有Exchange邮箱访问权限。m_exchangeService.AutodiscoverUrl(UserPrincipal.Current.EmailAddress,RedirectionUrlValidationCallbaCK);}publicExchangeServiceService{get{returnm_exchangeService;}}publicFolderGetPublicFolderByPath(stringewsFolderPath){string[]folders=ewsFolderPath.Split('\');文件夹parentFolderId=null;文件夹actualFolder=null;for(inti=0;ifolderName.Equals(folder.DisplayName,StringComparison.InvariantCultureIgnoreCase)))返回文件夹;thrownewException("找不到顶级文件夹:"+folderName);}privateFolderGetFolder(FolderIdparentFolderId,stringfolderName){FindFoldersResultsfindFolderResults=m_exchangeService.FindFolders(parentFolderId,newFolderView(int.MaxValue));foreach(FolderfolderinfindFolderResults.Where(folder=>folderName.Equals(folder.DisplayName,StringComparison.InvariantCultureIgnoreCase)))返回文件夹;thrownewException("找不到文件夹:"+folderName);}只读ExchangeServicem_exchangeService;}}本文来自网络收集,不代表立场,如涞及武权请点击右侧联系管理员删除。如需转载请注明出处: