การสนทนาทั่วไป How to upload attachment in a list using client object model?

  • 29 มีนาคม 2553 13:51
     
     

    I need to upload attachment in a custom list using client object model. Below is my code. M able to add new item but nothing happening while adding attachments. Not any error even.

    NetworkCredential credentials = new System.Net.NetworkCredential("username", "Password", "domain"); 

    ClientContext cnt = new ClientContext("mossserver");                    

                        cnt.Credentials = credentials;
                        cWeb = cnt.Web;
                        cnt.Load(cWeb);
                        cList = cnt.Web.Lists.GetByTitle("Idea");
                        cnt.Load(cList);

                        itemid = InsertData();
                        cListItem = cList.GetItemById(itemid);
                        cnt.Load(cListItem);
                        FileSaveBinaryInformation fsbInfo = new FileSaveBinaryInformation();
                        fsbInfo.CheckRequiredFields = false;
                        fsbInfo.Content = btFileBytes;
                        //cListItem.File.CheckOut();
                        cListItem.File.SaveBinary(fsbInfo);
                        //cListItem.File.CheckIn("Comment here", CheckinType.OverwriteCheckIn);
                        cListItem.Update();
                        //cList.Update();
                        cnt.Load(cListItem);
                        cnt.ExecuteQuery();