private void Move(Page page, Page newParent) { if (page.Node != newParent.Node && !newParent.PageIdentifier.StartsWith(page.PageIdentifier)) { string sourcePath = page.PageIdentifier; string newParentPath = newParent.PageIdentifier; CommonXml.Move(page.TreeNode, newParent.TreeNode); Save(); string newContainerDirectory = GetDocumentDirectory(newParentPath.Replace("/", @"\")); string sourceDirectory = GetDocumentDirectory(sourcePath.Replace("/", @"\")); string sourceFile = GetDocumentFilename(sourcePath.Replace("/", @"\")); // Ensure that the container directory exists Directory.CreateDirectory(newContainerDirectory); // Move file Common.MoveFile(sourceFile, newContainerDirectory); // Copy directory if (Directory.Exists(sourceDirectory)) { Common.CopyDirectory(sourceDirectory, Path.Combine(newContainerDirectory, page.Name), true); } // (Try to) Remove original directory try { Common.DeleteDirectory(sourceDirectory); } catch { throw new Exception("Cannot delete original Directory"); } Save(); } else { throw new Exception("Cannot move page to child"); } }