none
Exchange EWS Managed - Getting full path for a folder RRS feed

  • Question

  • Hi,

    I'm providing a mechanism to search for folders by name. Of course, folders may have the same name as long as their parent is different. In the resulting list therefore, I need to provide the full folder path (from root to leaf folder). In OL, there's a fullname property. Is there such an equivalent in EWS?

    Friday, May 11, 2012 2:16 PM

Answers

  • You can show the Folder path in EWS using the PR_FOLDER_PATHNAME Extended property this returns the fullpath to a folder that is delimited by the byte order mark FE-FF so if you want to return a \ delimited path you need to replace these values in the Unicode string that is returned when you retrieve this property eg

    static void getPath(ExchangeService service) {
    ExtendedPropertyDefinition PR_Folder_Path = new ExtendedPropertyDefinition(26293, MapiPropertyType.String);
    PropertySet psPropSet = new PropertySet(BasePropertySet.FirstClassProperties) { PR_Folder_Path };
    Folder foFolder = Folder.Bind(service, WellKnownFolderName.RecoverableItemsDeletions, psPropSet);
    Object fpPath = null;
    foFolder.TryGetProperty(PR_Folder_Path,out fpPath);
    String fpPathString = Encoding.Unicode.GetString(HexStringToByteArray(BitConverter.ToString(UnicodeEncoding.Unicode.GetBytes((String)fpPath)).Replace("FE-FF", "5C-00").Replace("-", "")));
    Console.WriteLine(fpPathString);
    }
    
    static Byte[] HexStringToByteArray(String HexString)
    {
    Byte[] ByteArray = new Byte[HexString.Length / 2];
    for (int i = 0; i < HexString.Length; i += 2)
    {
    ByteArray[i / 2] = Convert.ToByte(HexString.Substring(i, 2), 16);
    }
    return ByteArray;
    }
    Cheers
    Glen
    Monday, May 14, 2012 6:50 AM

All replies

  • To be more precise, in OL, the property is FullFolderPath
    Friday, May 11, 2012 2:25 PM
  • You can show the Folder path in EWS using the PR_FOLDER_PATHNAME Extended property this returns the fullpath to a folder that is delimited by the byte order mark FE-FF so if you want to return a \ delimited path you need to replace these values in the Unicode string that is returned when you retrieve this property eg

    static void getPath(ExchangeService service) {
    ExtendedPropertyDefinition PR_Folder_Path = new ExtendedPropertyDefinition(26293, MapiPropertyType.String);
    PropertySet psPropSet = new PropertySet(BasePropertySet.FirstClassProperties) { PR_Folder_Path };
    Folder foFolder = Folder.Bind(service, WellKnownFolderName.RecoverableItemsDeletions, psPropSet);
    Object fpPath = null;
    foFolder.TryGetProperty(PR_Folder_Path,out fpPath);
    String fpPathString = Encoding.Unicode.GetString(HexStringToByteArray(BitConverter.ToString(UnicodeEncoding.Unicode.GetBytes((String)fpPath)).Replace("FE-FF", "5C-00").Replace("-", "")));
    Console.WriteLine(fpPathString);
    }
    
    static Byte[] HexStringToByteArray(String HexString)
    {
    Byte[] ByteArray = new Byte[HexString.Length / 2];
    for (int i = 0; i < HexString.Length; i += 2)
    {
    ByteArray[i / 2] = Convert.ToByte(HexString.Substring(i, 2), 16);
    }
    return ByteArray;
    }
    Cheers
    Glen
    Monday, May 14, 2012 6:50 AM