none
Public folder is getting created but properties are not getting set properly RRS feed

  • Question

  • Hi,
    I have used below code which uses WebDev to create the public folder and setting its property. The public folder is getting created everytime successfully but the property is not getting set properly for "mailenabled" flag. Some times mailenabled property also getting set but it never create the publicfolderemailadrress (<e:publicfolderemailaddress>" + smtpAddress + "</e:publicfolderemailaddress>";) property never getting set though it gives return status Multi-Status. Could any one please help me what is wrong with my code.

    using System;
    
    
    
    using System.Collections.Generic;
    
    
    
    using System.Text;
    
    
    
    using System.Net;
    
    
    
    namespace PFCreator
    
    
    
    {
    
    
    
    class Program
    
    
    
    {
    
    
    
    static void Main(string[] args)
    
    
    
    {
    
    
    
    string serverURL = args[0];
    
    
    
    string newFolderName = args[1];
    
    
    
    string mailEnable = args[2];
    
    
    
    string smtpAddress = args[3];
    
    
    
    string strPFUri = "http://" + serverURL + "/public" + newFolderName;
    
    
    
    if (createPublicFolder(strPFUri) && setFolderProperties(strPFUri, mailEnable, smtpAddress))
    
    
    
    { 
    
    
    
    System.Console.WriteLine("Folder created successfully.");
    
    
    
    System.Environment.Exit(0);
    
    
    
    } 
    
    
    
    }
    
    
    
    //private static bool createPublicFolder(String pfPath, User user)
    
    
    
    private static bool createPublicFolder(string pfPath)
    
    
    
    {
    
    
    
    try
    
    
    
    { 
    
    
    
    // Create the HttpWebRequest object.
    
    
    
    WebRequest Request = (System.Net.HttpWebRequest)HttpWebRequest.Create(pfPath);
    
    
    
    Request.Credentials = CredentialCache.DefaultCredentials;
    
    
    
    Request.Method = "MKCOL";
    
    
    
    
    
    // Get the response from the server.
    
    
    
    WebResponse Response = Request.GetResponse();
    
    
    
    Console.WriteLine("Status(PF Creation): " + ((HttpWebResponse)Response).StatusDescription);
    
    
    
    Response.Close();
    
    
    
    }
    
    
    
    catch (Exception ex)
    
    
    
    {
    
    
    
    Console.WriteLine("Exception while creating Public Folder: " + ex.Message);
    
    
    
    Console.WriteLine("Stack Trace: " + ex.StackTrace);
    
    
    
    return false;
    
    
    
    }
    
    
    
    return true; 
    
    
    
    }
    
    
    
    private static bool setFolderProperties(string pfPath, string mailEnable, string smtpAddress)
    
    
    
    {
    
    
    
    try
    
    
    
    {
    
    
    
    byte[] bytes = null;
    
    
    
    System.IO.Stream RequestStream = null;
    
    
    
    
    
    // Create the XML
    
    
    
    string xmlstr = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>"
    
    
    
    + "\n<a:propertyupdate xmlns:a=\"DAV:\" " 
    
    
    
    + "xmlns:b=\"urn:schemas-microsoft-com:datatypes\" " 
    
    
    
    + "xmlns:e=\"http://schemas.microsoft.com/exchange/\" "
    
    
    
    + "xmlns:p=\"http://schemas.microsoft.com/mapi/proptag/\"> "
    
    
    
    + "\n<a:set><a:prop>"
    
    
    
    + "\n<e:outlookfolderclass>IPF.Folder</e:outlookfolderclass>"
    
    
    
    + "\n<a:contentclass>urn:content-classes:folder</a:contentclass>";
    
    
    
    if (mailEnable == "1")
    
    
    
    {
    
    
    
    xmlstr = xmlstr + "\n<p:0x3FE6000B b:dt=\"boolean\">1</p:0x3FE6000B>"
    
    
    
    + "\n<p:0x671F000B b:dt=\"boolean\">1</p:0x671F000B>"
    
    
    
    + "\n<e:publicfolderemailaddress>" + smtpAddress + "</e:publicfolderemailaddress>";
    
    
    
    }
    
    
    
    xmlstr = xmlstr + "\n</a:prop></a:set></a:propertyupdate>";
    
    
    
    Console.WriteLine("Properties:\n" + xmlstr);
    
    
    
    // Create the HttpWebRequest object.
    
    
    
    WebRequest Request = (System.Net.HttpWebRequest)HttpWebRequest.Create(pfPath);
    
    
    
    Request.Credentials = CredentialCache.DefaultCredentials;
    
    
    
    Request.Method = "PROPPATCH";
    
    
    
    Request.ContentType = "text/xml";
    
    
    
    Request.ContentLength = xmlstr.Length;
    
    
    
    Request.Headers.Add("Translate", "f");
    
    
    
    // Encode the body using UTF-8.
    
    
    
    bytes = Encoding.UTF8.GetBytes(xmlstr);
    
    
    
    // Set the content header length. This must be
    
    
    
    // done before writing data to the request stream.
    
    
    
    Request.ContentLength = bytes.Length;
    
    
    
    // Get a reference to the request stream.
    
    
    
    RequestStream = Request.GetRequestStream();
    
    
    
    // Write the message body to the request stream.
    
    
    
    RequestStream.Write(bytes, 0, bytes.Length);
    
    
    
    // Close the Stream object to release the connection
    
    
    
    // for further use.
    
    
    
    RequestStream.Close();
    
    
    
    // Get the response from the server.
    
    
    
    // Expected response: 207 Multi-Status - HTTP_MULTI_STATUS - The action was successfully received, understood, 
    
    
    
    // and accepted. Indicates that the client’s request was successfully received, understood, and accepted.
    
    
    
    WebResponse Response = Request.GetResponse();
    
    
    
    Console.WriteLine("Status(Property settings): " + ((HttpWebResponse)Response).StatusCode + " : " + ((HttpWebResponse)Response).StatusDescription);
    
    
    
    Response.Close();
    
    
    
    }
    
    
    
    catch (Exception ex)
    
    
    
    {
    
    
    
    Console.WriteLine("Exception while setting properties: " + ex.Message);
    
    
    
    Console.WriteLine("Stack Trace: " + ex.StackTrace);
    
    
    
    return false;
    
    
    
    }
    
    
    
    return true;
    
    
    
    } 
    
    
    
    }
    
    
    
    }
    
    
    
    

     

    • Edited by CSharpLeader Sunday, March 29, 2009 12:40 PM added few line
    Sunday, March 29, 2009 12:39 PM

Answers

All replies

  • Hi MeghaP.

    The Microsoft people usually chip in before now, but I'll try to assist. Unfortunately, I don't know much about this one.

    1. This probably isn't the right forum. You really need to find one about C#, .NET and web services; or rephrase your question in terms of an Exchange specification. I'm not sure where the right forum is, but perhaps http://social.msdn.microsoft.com/Forums/en-US/asmxandxml/threads?

    2. Maybe you need to call UpdateFolder()? http://msdn.microsoft.com/en-us/library/aa580257.aspx

    Hope that helps.
    • Proposed as answer by Brad Hards Monday, March 30, 2009 3:52 AM
    Monday, March 30, 2009 3:50 AM
  • Thanks Brad for your help. My question is nothing do with C# or Web Services. I have given it just for explanation. I just want to confirm that below XML structure to set the Public property is correct or anything is wrong because it set mailenabled property some times but the publicfolderemailadrress (<e:publicfolderemailaddress>" + smtpAddress + "</e:publicfolderemailaddress>";) property never getting set though it gives return status Multi-Status

    string xmlstr = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>"



    + "\n<a:propertyupdate xmlns:a=\"DAV:\" "



    + "xmlns:b=\"urn:schemas-microsoft-com:datatypes\" "



    + "xmlns:e=\"http://schemas.microsoft.com/exchange/\" "



    + "xmlns:p=\"http://schemas.microsoft.com/mapi/proptag/\"> "



    + "\n<a:set><a:prop>"



    + "\n<e:outlookfolderclass>IPF.Folder</e:outlookfolderclass>"



    + "\n<a:contentclass>urn:content-classes:folder</a:contentclass>";



    if (mailEnable == "1")



    {



    xmlstr = xmlstr + "\n<p:0x3FE6000B b:dt=\"boolean\">1</p:0x3FE6000B>"



    + "\n<p:0x671F000B b:dt=\"boolean\">1</p:0x671F000B>"



    + "\n<e:publicfolderemailaddress>" + smtpAddress + "</e:publicfolderemailaddress>";



    }



    xmlstr = xmlstr + "\n</a:prop></a:set></a:propertyupdate>";
    Monday, March 30, 2009 11:22 AM
  • Hi Megha,

    Thank you for contacting us and your interest in Exchange development.  As Brad has pointed out this forum is for discussion around the technical content of the Exchange Server 2007 protocols documents found here.

    You would be better served by developers on the Exchange Development forum that may be able to assist you with your solution. I suggest you post your question to the Microsoft TechNet > Forums Home > Exchange Server > Development forum found here.

    When posting to this forum please provide background information about your environment and proposed solution such as:

    Exchange Server version.
    Description of your Exchange topology that includes the OS.
    Providing this background information will better enable other developers to help you with your solution.

    I have asked some of the developers internally for feedback to see if there is something that is obvious and possibily missing from the protocol documentation described above.
    Developer Consultant
    Tuesday, March 31, 2009 4:37 AM
    Moderator
  • I got some great feedback from Dan Bagley (here is his blog http://blogs.msdn.com/webdav_101/default.aspx)

    He said that to do this properly with Exchange 2000 & 2003, you will need to use CDOEX and CDOEXM to mail enable a public folder.  It should also work with Exchange 2007.

    For Exhange 2007, you would use Exchange PowerShell:  http://technet.microsoft.com/en-us/library/aa997560.aspx.   If the Exchange Server is 2007, then absolutely use PowerShell over all other APIs.

    To set certain properties with WebDAV, the code would need to use an Exchange Admin account and the exadmin path (virtual folder) to the public folder.  The exadmin path helps get exchange admin privs when an exchange admin account is used. 

    Dan has has not done this before using just WebDAV.  Dan also recommended that you check Glen’s blog.  Glen is an MVP and knows messaging APIs well.

    http://gsexdev.blogspot.com/2005/10/mail-enabling-public-folder-via-mapi.html


    Developer Consultant
    Tuesday, March 31, 2009 10:29 PM
    Moderator
  • Could you please give me such example using CDOEX and CDOEXM to mail enable a public folder.

    Thanks,
    Megha
    Monday, April 20, 2009 5:42 AM
  • This forum is for supporting the technical discussion of Exchange Server protocol documentation.  You would be much better served by posting your follow-up question to the Microsoft TechNet > Forums Home > Exchange Server > Development  forum.  Make sure you include the version[s] of Exchange you intend to implement your solution against along with your development environment (for example c#).

     

    Also Matt Stehle, from Developer Support, has a good blog post “Why are MAPI and CDO 1.21 not supported in managed (.NET) code

     


    Developer Consultant
    Thursday, April 30, 2009 5:21 PM
    Moderator