Need example to create thread with attachment

Hi Team,

We are using Forum Thread resd endpoint to create thread.

Using the REST api i.e 

api.ashx/v2/forums/{forumid}/threads.xml 

It is working fine if I create only thread without attachments.

var values = new NameValueCollection();
values["Subject"] = "Attachment thread";
values["Body"] = "All about Attachments";

But If I try to use below fields i.e

values["FileName"]="TestAttachment";

values["FileData"] = BytesData;

It is not working. Could you please give me one sample example how to achieve thread with attachment functionality?

Thanks in advance.

  • In reply to Tony Triguero:

    Tony,

    Could you please provide me the code for ThreadParser and ThreadResponse.

    If it is not possible, tell me the way to overcome those errors.

    Thanks in advance.

  • In reply to KrishnaSandeep:

    You could just do something like the following - I am not going to say this is the best way to do this, but it is the best I can do when typing into a rich text editor.  This code is not tested and is just one idea to get you past your error.

    The idea would be to just have your routine return back the ThreadId (type INT) as opposed to the complex types for which you do not have the code.  If you need more information about the thread, you might have to parse the XML response.

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

    Change the return type to type "Int" - the new Thread Id you will be creating

    http://telligent.com/community/developers/w/developer7/29100.forumthread-in-process-api-supplementary-type.aspx 

    public static Int CreateThreadWithAttachment(int forumId.....

    Change the below code :

    ThreadResponse response = new ThreadResponse();

    -- CHANGE TO --

    int responseId;

    Change the code below:

                    using (var webResponse = request.GetResponse())
                    {
                        response = ThreadParser.ParseThreadReponse(webResponse.GetResponseStream());
                    }

    --CHANGE TO --
    using (var webResponse = request.GetResponse()) { string responseXml = webResponse.GetResponseStream();
    XDocument doc = XDocument.Parse(responseXml);

    // Get the ThreadId from the response XML var threadIdNode= dox.Descendants().Where(n => n.Name == "Id").FirstOrDefault(); string nodeValue; if (node != null) { nodeValue = node.Value;
    responseId = Convert.ToInt32(nodeValue);

    } }

    Finally, change the return at the end of the document

    return responseId;

  • In reply to Luke D:

    To add on to 's answer, those 2 classes are not really relevant to your issue, they are simply the way his code is handling the xml and dealing with it.  This functionality is up to you to implement.  Lukes solution may help you get going faster

Related