locked
Using WebDAV to Add a Folder Home Page RRS feed

  • Question

  • Hi,

    I'm trying to modify a folder I've already created via WebDAV in C# using this blog post as a reference. I cannot for the life of me figure out how I'm supposed to provide the Web View Folder info data in the format they've shown. I cannot even duplicate how they've arrived at the base64-encoded values that they have, using the data they have on that page.

    Can anyone lend me a hand on how to arrive at the proper format for the data in the PROPPATCH command I'm attempting to send?

    Thanks!
    Wednesday, July 22, 2009 12:13 AM

Answers

  • Okay well here's a c# sample for doing this using the EWS Managed API that works for me

            SetFolderHomePage(service, "/inbox/google", "www.google.com");
    
            static void SetFolderHomePage(ExchangeService service,String FldPath, String URL) {
                ExtendedPropertyDefinition PR_FOLDER_WEBVIEWINFO = new ExtendedPropertyDefinition(14047, MapiPropertyType.Binary);
                Folder mbRoot = Folder.Bind(service, WellKnownFolderName.MsgFolderRoot);
                String[] faFldArray = FldPath.Split('/');
                Folder tfTargetFolder = mbRoot;
                for (int lint = 1; lint < faFldArray.Length; lint++) {
                    FolderView fview = new FolderView(1);
                    fview.SearchFilter = new SearchFilter.IsEqualTo(FolderSchema.DisplayName, faFldArray[lint]);
                    FindFoldersResults ffResult = service.FindFolders(tfTargetFolder.Id, fview);
                    if (ffResult.TotalCount == 0)
                    {
                        Console.WriteLine("Folder Not Found");
                    }
                    else {
                        tfTargetFolder = ffResult.Folders[0];
                    }
                }
    
                tfTargetFolder.ExtendedProperties.Add(PR_FOLDER_WEBVIEWINFO, homepageval(URL));
                tfTargetFolder.Update();
            
            
            }
            static string homepageval(String url) {
                String homepageBytes = ConvertToHex(url);
                String dwVersion = "02";
                String dwType = "00000001";
                String dwFlags = "00000001";
                String dwUnused = "00000000000000000000000000000000000000000000000000000000";
                String cbDataSize = ((homepageBytes.Length / 2) + 2).ToString("X");
                String propval = dwVersion + dwType + dwFlags + dwUnused + "000000" + cbDataSize + "000000" + homepageBytes + "0000";
                Byte[] propByteArray = HexStringToByteArray(propval);
                return (Convert.ToBase64String(propByteArray));
            
            }
            static string ConvertToHex(string asciiString)
            {
                string hex = "";
                foreach (char c in asciiString)
                {
                    int tmp = c;
                    hex += String.Format("{0:x2}", (uint)System.Convert.ToUInt32(tmp.ToString())) + "00";
                }
                return hex;
            }
            static byte[] HexStringToByteArray(string Hex)
            {
                byte[] Bytes;
                int ByteLength;
                string HexValue = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\x9|||||||\xA\xB\xC\xD\xE\xF";
    
                ByteLength = Hex.Length / 2;
                Bytes = new byte[ByteLength];
    
                for (int x = 0, i = 0; i < Hex.Length; i += 2, x += 1)
                {
                    Bytes[x] = (byte)(HexValue[Char.ToUpper(Hex[i + 0]) - '0'] << 4);
                    Bytes[x] |= (byte)(HexValue[Char.ToUpper(Hex[i + 1]) - '0']);
                }
    
                return Bytes;
            }
    Thursday, July 23, 2009 12:27 AM

All replies

  • The format of the property isn't documented or supported http://blogs.msdn.com/pcreehan/archive/2007/12/19/folder-homepage-no-longer-works-in-outlook-2007-from-mapi-store-providers.aspx . So this is reverse engineer that myself and the others that posted to the comments had worked on. Basically its a byte array and then your Base64 encode that to post it. You might need to be bit more specific with your question if you have a piece of code that isn't working try posting your code. Its just a standard proppatch on a binary property eg

    <?xml version="1.0"?>
    <A:propertyupdate xmlns:A="DAV:" xmlns:B="http://schemas.microsoft.com/mapi/proptag/">
    <A:set>
    <A:prop>
    <B:x36DF0102>AAAA..etc(base64 encoded Hex)</B:x36DF0102>
    </A:prop>
    </A:set>
    </A:propertyupdate>
    Cheers
    Glen
    Wednesday, July 22, 2009 1:50 AM
  • Hi Glen,

    Thanks for the work you and the others have done toward this! I am currently just at the point of trying to duplicate the output found in the blog post.

    Here is some of the code that is not producing the data I expect:
    var versionEtc = "02000000010000000100000000000000000000000000000000000000000000000000000000000000";
    var hex = versionEtc + ((Url.Length + 1) * 2).ToString("X") + "00" + hexifiedUrl;
    
    // hex at this point is "020000000100000001000000000000000000000000000000000000000000000000000000000000002C0068007400740070003A002F002F006E006500770073002E006200620063002E0063006F002E0075006B00"
    
    // Now, if I convert that to a byte array and run it through Convert.ToBase64String() 
    
    var propVal = Convert.ToBase64String(Encoding.Default.GetBytes(hex));
    
    // I end up with
    // "MDIwMDAwMDAwMTAwMDAwMDAxMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAyQzAwNjgwMDc0MDA3NDAwNzAwMDNBMDAyRjAwMkYwMDZFMDA2NTAwNzcwMDczMDAyRTAwNjIwMDYyMDA2MzAwMkUwMDYzMDA2RjAwMkUwMDc1MDA2QjAw"
    Which doesn't look anything like what is in that blog post. Obviously how I'm creating the base 64 string from that hex is the problem, but I'm not sure what I'm doing wrong.

    Thanks!

    Wednesday, July 22, 2009 2:10 PM
  • Okay well here's a c# sample for doing this using the EWS Managed API that works for me

            SetFolderHomePage(service, "/inbox/google", "www.google.com");
    
            static void SetFolderHomePage(ExchangeService service,String FldPath, String URL) {
                ExtendedPropertyDefinition PR_FOLDER_WEBVIEWINFO = new ExtendedPropertyDefinition(14047, MapiPropertyType.Binary);
                Folder mbRoot = Folder.Bind(service, WellKnownFolderName.MsgFolderRoot);
                String[] faFldArray = FldPath.Split('/');
                Folder tfTargetFolder = mbRoot;
                for (int lint = 1; lint < faFldArray.Length; lint++) {
                    FolderView fview = new FolderView(1);
                    fview.SearchFilter = new SearchFilter.IsEqualTo(FolderSchema.DisplayName, faFldArray[lint]);
                    FindFoldersResults ffResult = service.FindFolders(tfTargetFolder.Id, fview);
                    if (ffResult.TotalCount == 0)
                    {
                        Console.WriteLine("Folder Not Found");
                    }
                    else {
                        tfTargetFolder = ffResult.Folders[0];
                    }
                }
    
                tfTargetFolder.ExtendedProperties.Add(PR_FOLDER_WEBVIEWINFO, homepageval(URL));
                tfTargetFolder.Update();
            
            
            }
            static string homepageval(String url) {
                String homepageBytes = ConvertToHex(url);
                String dwVersion = "02";
                String dwType = "00000001";
                String dwFlags = "00000001";
                String dwUnused = "00000000000000000000000000000000000000000000000000000000";
                String cbDataSize = ((homepageBytes.Length / 2) + 2).ToString("X");
                String propval = dwVersion + dwType + dwFlags + dwUnused + "000000" + cbDataSize + "000000" + homepageBytes + "0000";
                Byte[] propByteArray = HexStringToByteArray(propval);
                return (Convert.ToBase64String(propByteArray));
            
            }
            static string ConvertToHex(string asciiString)
            {
                string hex = "";
                foreach (char c in asciiString)
                {
                    int tmp = c;
                    hex += String.Format("{0:x2}", (uint)System.Convert.ToUInt32(tmp.ToString())) + "00";
                }
                return hex;
            }
            static byte[] HexStringToByteArray(string Hex)
            {
                byte[] Bytes;
                int ByteLength;
                string HexValue = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\x9|||||||\xA\xB\xC\xD\xE\xF";
    
                ByteLength = Hex.Length / 2;
                Bytes = new byte[ByteLength];
    
                for (int x = 0, i = 0; i < Hex.Length; i += 2, x += 1)
                {
                    Bytes[x] = (byte)(HexValue[Char.ToUpper(Hex[i + 0]) - '0'] << 4);
                    Bytes[x] |= (byte)(HexValue[Char.ToUpper(Hex[i + 1]) - '0']);
                }
    
                return Bytes;
            }
    Thursday, July 23, 2009 12:27 AM