Beispiel #1
0
        public static void Run()
        {
            // ExStart:RetrieveFolderPermissionsUsingExchangeWebServiceClient
            string folderName = "DesiredFolderName";

            // Create instance of EWSClient class by giving credentials
            IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");

            ExchangeFolderInfoCollection       folders     = client.ListPublicFolders();
            ExchangeFolderPermissionCollection permissions = new ExchangeFolderPermissionCollection();

            ExchangeFolderInfo publicFolder = null;

            try
            {
                foreach (ExchangeFolderInfo folderInfo in folders)
                {
                    if (folderInfo.DisplayName.Equals(folderName))
                    {
                        publicFolder = folderInfo;
                    }
                }

                if (publicFolder == null)
                {
                    Console.WriteLine("public folder was not created in the root public folder");
                }

                ExchangePermissionCollection folderPermissionCol = client.GetFolderPermissions(publicFolder.Uri);
                foreach (ExchangeBasePermission perm in folderPermissionCol)
                {
                    ExchangeFolderPermission permission = perm as ExchangeFolderPermission;
                    if (permission == null)
                    {
                        Console.WriteLine("Permission is null.");
                    }
                    else
                    {
                        Console.WriteLine("User's primary smtp address: {0}", permission.UserInfo.PrimarySmtpAddress);
                        Console.WriteLine("User can create Items: {0}", permission.CanCreateItems.ToString());
                        Console.WriteLine("User can delete Items: {0}", permission.DeleteItems.ToString());
                        Console.WriteLine("Is Folder Visible: {0}", permission.IsFolderVisible.ToString());
                        Console.WriteLine("Is User owner of this folder: {0}", permission.IsFolderOwner.ToString());
                        Console.WriteLine("User can read items: {0}", permission.ReadItems.ToString());
                    }
                }
                ExchangeMailboxInfo mailboxInfo = client.GetMailboxInfo();
                //Get the Permissions for the Contacts and Calendar Folder
                ExchangePermissionCollection contactsPermissionCol = client.GetFolderPermissions(mailboxInfo.ContactsUri);
                ExchangePermissionCollection calendarPermissionCol = client.GetFolderPermissions(mailboxInfo.CalendarUri);
            }
            finally
            {
                //Do the needfull
            }
            // ExEnd:RetrieveFolderPermissionsUsingExchangeWebServiceClient
        }