Search code examples
c#sharepointlistitem

How to update "list-item" in SharePoint directory


Here is my code for SharePoint.

 Microsoft.SharePoint.Client.File.SaveBinaryDirect(clientContext, fileUrl, bstream, false);
                    isAlreadyExists = false;
                    var file = clientContext.Web.GetFileByServerRelativeUrl(fileUrl);
                    clientContext.Load(file);
                    clientContext.ExecuteQuery();
                    DateTime dt = DateTime.Now;
                    Microsoft.SharePoint.Client.ListItem listItem = file.ListItemAllFields;
                    listItem[Utility.fieldNameSentReceived] = isSentOrReceived;
                    listItem[Utility.fieldNameSentBy] = msg.From.ToString();
                    listItem[Utility.fieldNameReceivedBy] = msg.To.ToString();
                    listItem[Utility.fieldNameSubject] = ((!msg.Subject.Contains("[" + ListCI.Title + "]")) ? "[" + ListCI.Title + "] " : string.Empty) + msg.Subject.ToString();
                    listItem[Utility.fieldNameSentReceivedDateTime] = dt;
                    listItem.Update();
                    clientContext.ExecuteQuery();
                    CreateCategoryIfNotExist(emailAddress);
                    SetCategoryToEmail(emailAddress, id);

I tried to update directory list-item(Header of directory). but it throws exception "Column 'SentORReceived' does not exist. It may have been deleted by another user."


Solution

  • Are you sure that column SentORReceived really exist?

    It should be internal name of a column. If you used different name when creating the column and then renamed, you need to use the original one.