Click here to Skip to main content
15,888,233 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi all,
In my experience with EWS, why is it necessary to add additional security right on Exchange when querying ExtendedProperty data. When I make use of the following code:

public ExtendedPropertyType[] GetExtendedProperties(ItemIdType itemid)
{
    PathToExtendedFieldType pathClassification = new PathToExtendedFieldType();
    pathClassification.DistinguishedPropertySetId = 
       DistinguishedPropertySetType.PublicStrings;
    pathClassification.DistinguishedPropertySetIdSpecified = true;
    pathClassification.PropertyName = "Classification";
    pathClassification.PropertyType = MapiPropertyTypeType.String;


    GetItemType getExPropertiesRequest = new GetItemType();
    ItemIdType iiItemId = new ItemIdType();
    iiItemId = itemid;

    ItemResponseShapeType getResponseShape = new ItemResponseShapeType();
    getResponseShape.BaseShape = DefaultShapeNamesType.AllProperties;
    getResponseShape.IncludeMimeContent = true;
    getExPropertiesRequest.ItemShape = getResponseShape;

    getExPropertiesRequest.ItemShape.AdditionalProperties = 
                                     new BasePathToElementType[1];
    getExPropertiesRequest.ItemShape.AdditionalProperties[0] = pathClassification;


    getExPropertiesRequest.ItemIds = new ItemIdType[1];
    getExPropertiesRequest.ItemIds[0] = iiItemId;
    getExPropertiesRequest.ItemShape.BaseShape = DefaultShapeNamesType.AllProperties;

    GetItemResponseType giResponse = _esb.GetItem(getExPropertiesRequest);
    if (giResponse.ResponseMessages.Items[0].ResponseClass == ResponseClassType.Error)
    {
        throw new Exception("Error: " +
        giResponse.ResponseMessages.Items[0].MessageText);
    }
    else
    {
        ItemInfoResponseMessageType rmResponseMessage = 
             giResponse.ResponseMessages.Items[0] as ItemInfoResponseMessageType;

        if (rmResponseMessage.Items.Items[0].ExtendedProperty != null)
        {
            MessageType message = rmResponseMessage.Items.Items[0] as MessageType;
            return (message.ExtendedProperty);
        }
        else
        {
            return null;
        }
    }
}


I require full access permissions, otherwise I cannot query extended property data.
Why is this? Could someone please explain?

I even tried developing against EWS API - here is the code:

class Program
    {
        static void Main(string[] args)
        {
            ServicePointManager.ServerCertificateValidationCallback =
                delegate(Object obj, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
                {
                    return true;
                };

            try
            {
                // Connect to Exchange Web Services as user1 at contoso.com.
                ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);
                service.Credentials = new NetworkCredential("user.name", "password123", Environment.UserDomainName);
                service.Url = new Uri("https://mailserver/EWS/Exchange.asmx");

                ItemView iv = new ItemView(30);
                FolderId Folderid = new FolderId(WellKnownFolderName.Calendar, "boardroomd123@qmuzik.com");
                FindItemsResults<Item> fiResults = service.FindItems(Folderid, iv);

                ExtendedPropertyDefinition rmsActivityProp = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, "OnQGuid", MapiPropertyType.String);
                ExtendedPropertyDefinition[] userFields = new ExtendedPropertyDefinition[] { rmsActivityProp };
                iv.PropertySet = new PropertySet(BasePropertySet.FirstClassProperties, userFields);
                FindItemsResults<Item> findResults = service.FindItems(Folderid, iv);

                Appointment appt = null;

                foreach (Item item in findResults.Items)
                {
                    if (item != null && item is Appointment)
                    {
                        appt = item as Appointment;

                        Console.ForegroundColor = ConsoleColor.Magenta;
                        Console.WriteLine("> Appointment Subject: {0}", appt.Subject);
                        Console.WriteLine("> Start Date: {0}", appt.Start);
                        Console.WriteLine("> End Date: {0}", appt.End);
                        Console.WriteLine("> Extended Properties Count: {0}", appt.ExtendedProperties.Count);

                        if (item.ExtendedProperties.Count > 0)
                        {
                            // Display the extended name and value of the extended property.
                            foreach (ExtendedProperty extendedProperty in item.ExtendedProperties)
                            {
                                Console.ForegroundColor = ConsoleColor.Cyan;
                                Console.WriteLine("# Extended Property Name: {0}", extendedProperty.PropertyDefinition.Name);
                                Console.WriteLine("# Extended Property Value: {0}", extendedProperty.Value);
                            }
                        }
                        else
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine("# NO Extended Property Data Found");
                        }

                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.WriteLine("-----------------------------------------------------------");
                    }                    
                }

                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Done....Processed: {0} Items", iv.PageSize);
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
                Console.ReadLine();
            }
        }
    }


And it still requires the additional security to query the extended properties? Here is the output when an user account has been configured without any permissions:
Error: The specified folder could not be found in the store.

Could someone please explain??

Many thanks again!
Kind regards,
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900