1

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?

4

1 回答 1

0

我终于找到了解决这个问题的方法。我不得不对我做事的方式做一些改变。特别是从十六进制接收值的转换,必须在没有 0x 前缀的情况下完成。

关键仍然是发送相同的 ThreadingIndex 值,在应用了一些晦涩的魔法之后。这是我用来添加对使用 SharePoint Web 服务 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);
        }
    }

希望这可以帮助

于 2010-08-19T15:49:39.037 回答