Question

I need to download all the ".wav" files inside a folder called "Recorded" on the user OneDrive. I'm using this code but the downloaded files are 0 kb. I can't find the error in this code.

LiveOperationResult operationResult = await client.GetAsync(folderId + "/files");

                var iEnum = operationResult.Result.Values.GetEnumerator();
                iEnum.MoveNext();
                var files = iEnum.Current as IEnumerable;

                foreach (dynamic v in files)
                {
                    var downloadOperationResult = await client.DownloadAsync(v.id as string);
                    using (Stream downloadStream = downloadOperationResult.Stream)
                    {
                        if (downloadStream != null)
                        {
                            using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
                            {
                                if (!storage.DirectoryExists("Recorded")) storage.CreateDirectory("Recorded");
                                using (
                                    IsolatedStorageFileStream fileToSave = storage.OpenFile("/Recorded/" + v.name as string,
                                        FileMode.Create, FileAccess.ReadWrite))
                                {
                                    downloadStream.CopyTo(fileToSave);
                                    downloadStream.Flush();
                                    downloadStream.Close();
                                }
                            }
                        }
                    }
                }
Was it helpful?

Solution

It looks like you are missing "/content" in your DownloadAsync call.

 var downloadOperationResult = await client.DownloadAsync(v.id+"/content" as string);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top