public OneDriveDirectory GetOneDriveDirectory(string fullPath) { if (string.IsNullOrEmpty(fullPath)) { return(null); } List <OneDriveDirectory> skydriveListing; OneDriveDirectory selectedEntry = null; // root listing. skydriveListing = ListOneDriveDirectoryWithUrl(""); var fileFound = false; var sp = fullPath.Split('/'); var searchDir = ""; foreach (var entry in sp.Where(x => x != "")) { var foundEntry = (from e in skydriveListing where e.Name == entry select e).FirstOrDefault(); if (foundEntry != null && foundEntry.Type == "folder") { searchDir = foundEntry.Id + "/"; skydriveListing = ListOneDriveDirectoryWithUrl(searchDir); } else { return(null); } selectedEntry = foundEntry; } return(selectedEntry); }
// complete path. eg, /firstdir/seconddir/thirddir public OneDriveDirectory CreateFolder(string folderPath) { // getting root folder. var rootList = ListOneDriveDirectoryWithUrl(""); string parentId = rootList[0].ParentId; var sp = folderPath.Split('/'); var directory = ""; OneDriveDirectory latestDir = null; foreach (var folder in sp.Where(x => x != "")) { directory += "/" + folder; var dir = GetOneDriveDirectory(directory); if (dir == null && directory != "") { CreateFolder(folder, parentId); dir = GetOneDriveDirectory(directory); } parentId = dir.Id; latestDir = dir; } return(latestDir); }
// fullPath is any number of directories then filename // eg. dir1/dir2/dir3/myfile.txt public OneDriveFile GetOneDriveEntryByFileNameAndDirectory(string fullPath) { if (string.IsNullOrEmpty(fullPath)) { return(null); } List <OneDriveDirectory> skydriveListing; OneDriveDirectory selectedEntry = null; OneDriveFile selectedFile = null; // root listing. skydriveListing = ListOneDriveDirectoryWithUrl(""); var fileFound = false; var sp = fullPath.Split('/'); var searchDir = ""; foreach (var entry in sp) { var foundEntry = (from e in skydriveListing where e.Name == entry select e).FirstOrDefault(); if (foundEntry != null && foundEntry.Type == "folder") { searchDir = foundEntry.Id + "/"; skydriveListing = ListOneDriveDirectoryWithUrl(searchDir); } // cant have == "file", since "photos" etc come up as different types. if (foundEntry != null && foundEntry.Type != "folder") { fileFound = true; var l = ListOneDriveFileWithUrl(foundEntry.Id); if (l != null) { selectedFile = l; } } selectedEntry = foundEntry; } if (!fileFound) { selectedFile = null; } return(selectedFile); }