0

I am trying to create a folder inside a folder

The parent folder is inside a document library

Below is my code

List<Folder> Affaires = GetAllFolders(oWeb.Lists.GetByTitle(LibraryName));
                    foreach(Folder Affaire in Affaires)
                    {
                        try
                        {
                            Folder folder = ctx.Web.GetFolderByServerRelativeUrl(Affaire.ServerRelativeUrl + "/Mails");
                            ctx.Load(folder);
                            ctx.ExecuteQuery();
                            Folder Sample = Affaire.Folders.Add("Sample");
                            //it goes to catch block after the below statement
                            ctx.ExecuteQuery();
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("");
                        }
}

I also tried

    Folder folder = ctx.Web.GetFolderByServerRelativeUrl("Site-580515/Affaires/Test Affaire");
                                ctx.Load(folder);
                                ctx.ExecuteQuery();
                               //it runs till next line
                                folder.Folders.Add("Demo");
                                ctx.ExecuteQuery();
0
var list = ctx.GetListByTitle("MyList);
list.EnableFolderCreation = true;
list.RootFolder.EnsureFolder("Folder1").EnsureFolder("SubFolderToFolder1");
ctx.ExecuteQuery();

This will create "Folder1" and subfolder "SubfolderToFolder1" if they do not exist.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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