Example #1
0
        private OneDriveFileList GetOneDriveRootListing()
        {
            var    accessToken = GetAccessToken();
            string jsonData;

            string url = string.Format(@"https://apis.live.net/v5.0/me/skydrive?access_token={0}", accessToken);

            using (var client = new WebClient())
            {
                var result = client.OpenRead(new Uri(url));
                var sr     = new StreamReader(result);
                jsonData = sr.ReadToEnd();
            }

            FileSystemBase driveInfo = JsonConvert.DeserializeObject <FileSystemBase>(jsonData);

            url = string.Format("{0}?access_token{1}", driveInfo.Upload_Location, accessToken);
            using (var client = new WebClient())
            {
                var result = client.OpenRead(new Uri(url));
                var sr     = new StreamReader(result);
                jsonData = sr.ReadToEnd();
            }

            OneDriveFileList rootList = JsonConvert.DeserializeObject <OneDriveFileList>(jsonData);

            return(rootList);
        }
Example #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            //GetSkydriveInfo();
            //GetSkyDriveRootFileListing();
            //GetStorageQuota();

            lsbOutput.Items.Add("Getting file list...");
            OneDriveFileList driveRoot = GetOneDriveRootListing();

            lsbOutput.Items.Add("Extracting images from list");
            List <FileSystemImage> myImages = GetIamgesFromFileList(driveRoot);

            lsbOutput.Items.Add("Downloading first image found");
            DownloadFile(driveRoot, myImages[0].ID);

            lsbOutput.Items.Add("Done.");
        }
Example #3
0
        private List <FileSystemImage> GetIamgesFromFileList(OneDriveFileList inputList)
        {
            List <FileSystemImage> results = new List <FileSystemImage>();

            using (var client = new WebClient())
            {
                var images = inputList.Data.Where(x => x.Type.Equals("photo"));
                foreach (var fileSystemBase in images)
                {
                    string url       = string.Format("{0}?access_token={1}", fileSystemBase.Upload_Location.Replace("content/", string.Empty), GetAccessToken());
                    var    webResult = client.OpenRead(new Uri(url));
                    var    sr        = new StreamReader(webResult);
                    var    jsonData  = sr.ReadToEnd();

                    results.Add(JsonConvert.DeserializeObject <FileSystemImage>(jsonData));
                }
            }

            return(results);
        }
Example #4
0
        private void DownloadFile(OneDriveFileList inputList, string fileIdToDownload)
        {
            var fileToDownload = inputList.Data.FirstOrDefault(x => x.ID == fileIdToDownload);

            if (fileIdToDownload == null)
            {
                return;
            }
            using (var client = new WebClient())
            {
                string url       = string.Format("{0}?access_token={1}", fileToDownload.Upload_Location, GetAccessToken());
                var    webResult = client.OpenRead(new Uri(url));
                if (webResult == null)
                {
                    return;
                }
                using (var fileStream = File.Create(fileToDownload.Name))
                {
                    webResult.CopyTo(fileStream);
                }
            }
        }