I have a utility function to copy documents from one folder to another folder in SharePoint Online using C#/CSOM. It works well for subfolders, but I am having issues with RootFolders for libraries.
For example, this will get the root list for a subfolder. I use the return List for other tasks like copying content types, fields, and other configuration for the copied documents:
public static List Foo(Folder bar)
{
return bar.ListItemAllFields.ParentList;
}
Problem is, when I pass a List.RootFolder object to this function (which uses the Folder class), there is an error because ListItemAllFields is null. The question is how do I get the parent list with just the Folder as a parameter if the folder's ListItemAllFields property is null? This does not work:
public static void FooBar(List list)
{
List self = Foo(list.RootFolder);
}
public static List Foo(Folder bar)
{
return bar.ListItemAllFields.ParentList;
}
Thanks