Sharepoint 2007: Reply to a discussion board item
Once you dive into the SPS 2007 API, you'll find a method called CreateNewDiscussionReply(SPListItem parent) (SPUtility.CreateNewDiscussionReply). Now in theory, and as the name suggests, this should post a reply to a topic in a discussionboard. Unfortunately though, it doesn't, or at least, only when it feels like giving you a little hope, it would post it (in the right location).
After hours of utter frustration and a lot of smoke breaks, we (a colleague and I) finally found a very long workaround that actually works for posting a reply on a discussion board, here is the code we used:
WindowsImpersonationContext wic = WindowsIdentity.GetCurrent().Impersonate();
SPList list = site.GetList(BoardUrl);
SPListItem rep = null;
SPListItem parent = list.GetItemByUniqueId(guid);
string folderPath = @"/" + parent.Folder;
string path = HttpUtility.HtmlEncode(folderPath);
folderPath = path;
rep = parent.ListItems.Add(path, SPFileSystemObjectType.File);
rep.Properties["DiscussionReply"] = Message;
rep["Title"] = OriginalMessage;
rep["Body"] = Message;
rep["Category"] = category;
rep.Update();
wic.Undo();
The BoardUrl is just the full url of the discussionboard you would like to post the reply to.
The guid is the Guid of the parent item you want to reply to, there are various ways of getting the parent item, we used the SPList.GetListItems() method, and then ran through the xml returned until we found the item we want to reply to, then got the guid from there.
To add a list item isn't really the problem, the problem is to get SPS to recognise it as a reply, which is done with:
rep.Properties["DiscussionReply"] = Message;
Where Message is the body of the reply.
We've ran into all sorts of problems with the API and web services for SPS2007 so far, but fortunately there are ways to work around them. I must give credit to Riaan for this code though, as he figured out most it, and finally got it working.
Good luck. IHTH