views:

216

answers:

2

I have a discussion board in SharePoint 2007 in which I want to view all discussions and their replies on the same page. For example I have 3 discussions within the discussion board and some replies. I want something like the following output to be displayed on a page:

(+) discussion no. 1     replies:3 

(+) discussion no. 2     replies:1

(+) discussion no. 3     replies:0

and then when I click on expand (+), I want to view all the replies for each discussion:

(-) discussion no. 1      replies:3  

      (+) this is the reply to discussion no. 1

      (+) this is the 2nd reply to discussion no. 1

(+) discussion no. 2      replies:1

(+) discussion no. 3      replies:0

Does anyone know how to go about doing this?

A: 

Hi I have the same doubt, in particular using SharePoint web services API, I've been trying with the AddDiscussionBoardItem method, but posting replies doesnt work, I can't get the Threading-Index right

gabouy
A: 

I've finally found the fix for this. I had to do some changes in the way I was doing things. In particular the conversion of the received value from hex, must be done without the 0x prefix.

The key is still to send the same ThreadingIndex value, after applying some obscure magic with it. Here's the code I'm using to add a reply to a discussion using SharePoint web services api:

        String trimmedBody = itemNode.Attributes.GetNamedItem("ows_BodyAndMore").Value;
        String threadIndex = itemNode.Attributes.GetNamedItem("ows_ThreadIndex").Value;

        StringBuilder mesBody = new StringBuilder(1024);

        mesBody.AppendFormat("Message-ID: {0}\n", Guid.NewGuid().ToString());

        threadIndex = threadIndex.Substring(2);
        byte[] byteArray = FromHex(threadIndex);                        
        threadIndex = base64Encode(byteArray);
        string encoded = threadIndex;

        mesBody.AppendFormat("Thread-Index: {0}\n", encoded);
        mesBody.AppendFormat("Subject: {0}\n", title); //the ows_Title of the discussion - messages don't always have titles...
        mesBody.Append("Mime-Version: 1.0\n");
        mesBody.Append("Content-type: text/html; charset=UTF-8\n\n");
        mesBody.Append(body);
        mesBody.Append(trimmedBody);
        client.AddDiscussionBoardItem(ListName, Encoding.UTF8.GetBytes(mesBody.ToString()));

    public static byte[] FromHex(string hex)
    {
        hex = hex.Replace("-", "");
        byte[] raw = new byte[hex.Length / 2];
        for (int i = 0; i < raw.Length; i++)
        {
            raw[i] = Convert.ToByte(hex.Substring(i * 2, 2), 16);
        }
        return raw;
    }

    public string base64Encode(byte[] data)
    {
        try
        {
            byte[] encData_byte = data;
            string encodedData = Convert.ToBase64String(encData_byte);
            return encodedData;
        }
        catch (Exception e)
        {
            throw new Exception("Error in base64Encode" + e.Message);
        }
    }

hope this helps

gabouy