Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I've been trying to update the file name of a document inside of a doc set. I continually get either a "Invalid data has been used to update the list item. The field you are trying to update may be read only." error or an "item is checked out to ..." error

Here is what I'm trying:

        foreach (Folder folder in documentsList.RootFolder.Folders)
        {
            clientContext.Load(folder.Files);
            clientContext.ExecuteQuery();
            foreach (Microsoft.SharePoint.Client.File file in folder.Files)
            {
                if (file.Name == xfileName)
                {
                    file.ListItemAllFields["Document_x0020_Type"] = docType;
                    file.ListItemAllFields["LinkFilename"] = documentName;
                    file.ListItemAllFields.Update();
                    file.CheckIn("", CheckinType.MajorCheckIn);

                }

            }
            clientContext.ExecuteQuery();
        }

I've also tried:

                foreach (Folder folder in documentsList.RootFolder.Folders)
                {
                    clientContext.Load(folder.Files);
                    clientContext.ExecuteQuery();
                    foreach (Microsoft.SharePoint.Client.File file in folder.Files)
                    {
                        if (file.Name == xfileName)
                        {
file.CheckOut();
                            file.ListItemAllFields["Document_x0020_Type"] = docType;
                            file.ListItemAllFields["LinkFilename"] = documentName;
                            file.ListItemAllFields.Update();
                            file.CheckIn("", CheckinType.MajorCheckIn);
                            clientContext.ExecuteQuery();
                        }

                    }

                }

I can't seem to get this to work... Any help would be appreciated!

share|improve this question
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.