Quantcast
Channel: Exchange Server Development forum
Viewing all articles
Browse latest Browse all 7132

EWS deleting custom categories

$
0
0

Hello,

I have written a small app that allows a member of support to change the outlook delegate of a specified user by mereley entering the smtp address.  All was fine, so I thought till we changed the delegate for one of our board members.  The delegate changed but all the custom categories were deleted. 

Is there a way to prevent this from happening?

namespace Delegates
{
    public class Program
    {

        public static void Main()
        {
            Console.WriteLine("You are adding delegate permissions");
            Console.WriteLine();
            Console.WriteLine("Please enter the board member's email address:");
            var ownerUser = Console.ReadLine();

            Console.WriteLine("Please enter the PA's email address:");
            var delegateUser = Console.ReadLine();

            Console.WriteLine("Attempting to add '{0}' as a delegate for '{1}'", delegateUser, ownerUser);

            // Bind to the service by using the primary e-mail address credentials.
            ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
            service.Url = new Uri("https://p-slo-mail2010.aspectcapital.com/EWS/Exchange.asmx/");
            service.UseDefaultCredentials = true;
            service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, ownerUser);
            //service.Credentials = new NetworkCredential(adminUsername, adminPassword, "ASPECT");
            try
            {
                service.AutodiscoverUrl(ownerUser);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            DelegateUser newDelegate1 = new DelegateUser(delegateUser);

            newDelegate1.Permissions.CalendarFolderPermissionLevel = DelegateFolderPermissionLevel.Editor;
            newDelegate1.Permissions.InboxFolderPermissionLevel = DelegateFolderPermissionLevel.Editor;
            newDelegate1.ReceiveCopiesOfMeetingMessages = true;

            Mailbox mailbox1 = new Mailbox(ownerUser);

            List<UserId> remove = new List<UserId>();

            DelegateInformation result1 = service.GetDelegates(mailbox1, true);

            if (result1.DelegateUserResponses.Count > 0)
            {
                foreach (DelegateUserResponse delegateUserResponse in result1.DelegateUserResponses)
                {
                    remove.Add(delegateUserResponse.DelegateUser.UserId);

                }

                Collection<DelegateUserResponse> response = service.RemoveDelegates(mailbox1, remove);
            }
            var resp = service.AddDelegates(mailbox1, MeetingRequestsDeliveryScope.DelegatesAndMe, newDelegate1);

            if (resp.Any(r => r.Result != ServiceResult.Success))
            {
                Console.WriteLine("Problem adding delegate");
            }

            Collection<DelegateUserResponse> result2 = service.UpdateDelegates(mailbox1, MeetingRequestsDeliveryScope.DelegatesAndMe, newDelegate1);

            if (result2.Any(r => r.Result != ServiceResult.Success))
            {
                Console.WriteLine("Problem setting delegate permissions");
            }

        }
    }
}


Kind Regards djsd



Viewing all articles
Browse latest Browse all 7132

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>