0

My scenario: I have a list that i am iterating to get all subfolders files and updating those files. I cant seem to get to the list item name to pass a parameter for FolderserverRelativeUrl.

foreach (ListItem item in folderItems)
            {
                if (item.FileSystemObjectType == FileSystemObjectType.File)
                {
                    item["Title"] = "Test";
                    item.Update();
                    list.Update();
                    clientContext.ExecuteQuery();

                }
                else if (item.FileSystemObjectType == FileSystemObjectType.Folder)
                {
                    // item is a folder
                    String SubFolderUrl = folderServerRelativeUrl + "/" + item["Title"]; 

                    GetFolderItems(SubFolderUrl, list,clientContext);

                }
            }
2
  • can you try using item["FileLeafRef"] ? Mar 15, 2018 at 6:25
  • @GautamSheth great it works but now,i can see my files have been modified in the modified column but nothing seem to have happened,i just need to update a column for that item. Mar 15, 2018 at 6:34

1 Answer 1

2

As mentioned in comments, you need to use the built-in field, FileLeafRef.

FileLeafRef is the field which contains the actual name of the file in a document library.

Secondly, in your code I see that you are passing the folderServerRelativeUrl.

You can probably replace that with FileRef which is another built-in field containing the server-relative URL of the file in a doc lib.

The code can be somewhat as below:

// item is a folder
String SubFolderUrl = item["FileRef"]; 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.