locked
AddDiscussionBoardItem RRS feed

  • Question

  • Has anybody used the 'AddDiscussionBoardItem' method thats part of the list.asmx webservice? I'm trying to call it using jquery but not sure as to what goes into the message parameter.

    Help is appreciated.
    • Edited by Mike Walsh FIN Wednesday, February 9, 2011 9:03 PM do not write Help with in titles
    Wednesday, October 21, 2009 6:58 PM

Answers

  • Hi,

            You can used 'AddDiscussionBoardItem' method like this:

          

           -----------------------------------------------------------------------------------------------

             public static void addDiscus()

             {

                Lists list = new Lists();

                list.Credentials = CredentialCache.DefaultCredentials;

                list.Url = siteurl + "/_vti_bin/Lists.asmx";

     

                string threadIndex = Base64Encoder.Encode ("" + Guid.NewGuid().ToString() + "@test");

                //For body

                string mime = "Message-ID: 99\n";

                mime += "Thread-Index: " + threadIndex + "\n";

                mime += "Subject: This is the topic\n";

                mime += "Mime-Version: 1.0\n";

                mime += "Content-type: text/plain; charset=us-ascii\n\n";

                mime += "This is the body of the topic\n";

     

                byte[] bytes = new byte[mime.Length];

                for (int i = 0; i < mime.Length; i++)

                    bytes[i] = (byte)mime[i];

     

                list.AddDiscussionBoardItem("{your list Guid}", bytes);

              

               //For reply

                mime = "Message-ID: 100\n";

                mime += "Thread-Index: " + threadIndex + "\n";

                mime += "Subject: This is the reply\n";

                mime += "Mime-Version: 1.0\n";

                mime += "Content-type: text/plain; charset=us-ascii\n\n";

                mime += "This is the body of the reply\n";

     

                bytes =

                new byte[mime.Length];

                for (int i = 0; i < mime.Length; i++)

                    bytes[i] = (byte)mime[i];

                list.AddDiscussionBoardItem("{your list Guid }", bytes);

            }

             -----------------------------------------------------------------------------------------------

     

            Note: You must encode the threadindex string in Base64

            You can refer

            http://www.koders.com/csharp/fid7539E0D62CC49119F25936B94244C98C04B82AF7.aspx?s=mdef%3Asystem

    Hope this can help.     

    Best Regards,

    -Aaron

    Tuesday, October 27, 2009 9:51 AM

All replies

  • Hi,

            You can used 'AddDiscussionBoardItem' method like this:

          

           -----------------------------------------------------------------------------------------------

             public static void addDiscus()

             {

                Lists list = new Lists();

                list.Credentials = CredentialCache.DefaultCredentials;

                list.Url = siteurl + "/_vti_bin/Lists.asmx";

     

                string threadIndex = Base64Encoder.Encode ("" + Guid.NewGuid().ToString() + "@test");

                //For body

                string mime = "Message-ID: 99\n";

                mime += "Thread-Index: " + threadIndex + "\n";

                mime += "Subject: This is the topic\n";

                mime += "Mime-Version: 1.0\n";

                mime += "Content-type: text/plain; charset=us-ascii\n\n";

                mime += "This is the body of the topic\n";

     

                byte[] bytes = new byte[mime.Length];

                for (int i = 0; i < mime.Length; i++)

                    bytes[i] = (byte)mime[i];

     

                list.AddDiscussionBoardItem("{your list Guid}", bytes);

              

               //For reply

                mime = "Message-ID: 100\n";

                mime += "Thread-Index: " + threadIndex + "\n";

                mime += "Subject: This is the reply\n";

                mime += "Mime-Version: 1.0\n";

                mime += "Content-type: text/plain; charset=us-ascii\n\n";

                mime += "This is the body of the reply\n";

     

                bytes =

                new byte[mime.Length];

                for (int i = 0; i < mime.Length; i++)

                    bytes[i] = (byte)mime[i];

                list.AddDiscussionBoardItem("{your list Guid }", bytes);

            }

             -----------------------------------------------------------------------------------------------

     

            Note: You must encode the threadindex string in Base64

            You can refer

            http://www.koders.com/csharp/fid7539E0D62CC49119F25936B94244C98C04B82AF7.aspx?s=mdef%3Asystem

    Hope this can help.     

    Best Regards,

    -Aaron

    Tuesday, October 27, 2009 9:51 AM
  • Aaron,

    Can you please demonstrate an example where we can post reply against a reply. How can we acheive threaded discussion creation with 'AddDiscussionBoardItem' web service method.
    Wednesday, February 17, 2010 1:25 PM
  • Your solution works for me to create discussion board entries using web services. However, when I then go to sharepoint on browser and try to reply to entry get following error:

    Failed to get value of the "Thread Index" column from the "ThreadIndex" field type control. Exception message: Value does not fall within the expected range..

     

    I notice the 64Encoded thread index used for AddDiscussionItem is 0x(72 digits) while the thread index for an item created through SP browser is 0x(44 digits).

    Could this be the problem? I use to following code to Base64Encode:

    byte[] encData_byte = new byte[data.Length];
            encData_byte = System.Text.Encoding.UTF8.GetBytes(data);   
            string encodedData = Convert.ToBase64String(encData_byte);

     

    Wednesday, February 9, 2011 8:03 PM
  • Hi Ing,

    instead of "string threadIndex = Base64Encoder.Encode(ItemGUID);" try this -

     

    sbyte[] ItemGUIDbytes = (sbyte[])(Array)System.Text.ASCIIEncoding.ASCII.GetBytes(ItemGUID);
    string threadIndex = Base64Encoder.Encode(ItemGUIDbytes);

    this worked for me

    Good luck

    James

     
    Thursday, March 24, 2011 11:59 AM