How to download files from OneDrive
Asked Answered
F

4

5

I am looking to download my files in public folder from One Drive, but it doesn't download the files. Here is the scenario:

In public folder I have another folder with multiple files in it and is accessible widely. for test purpose I have shared all the files in public folder (I don't if it's proper way of sharing it).

The following links are provided for me to download the file:

  1. From shared folder link https://onedrive.live.com/redir?resid=DBBC281099F4FE69!646&authkey=!AGRCGuw8Y2_p9mA&ithint=folder%2c.mp3
  2. From public folder link https://onedrive.live.com/redir?resid=DBBC281099F4FE69%21646
  3. Direct link http://1drv.ms/1z9XlW6 -

I am using BackgroundTransferRequest to download the file using below code:

string filePathToDownload = string.Empty, fileName = "111.mp3";
filePathToDownload = "http://1drv.ms/1z9XlW6";

Uri transferUri = new Uri(Uri.EscapeUriString(filePathToDownload), UriKind.RelativeOrAbsolute);
BackgroundTransferRequest transferRequest = new BackgroundTransferRequest(transferUri);
transferRequest.Method = "GET";
transferRequest.TransferPreferences = TransferPreferences.AllowCellularAndBattery;

Uri downloadUri = new Uri(DataSource.TEMPDOWNLOADLOCATION + fileName, UriKind.RelativeOrAbsolute);
transferRequest.DownloadLocation = downloadUri;
transferRequest.Tag = fileName;

The file is 300Kb, but this only downloads 6 Kb.

How can I directly download the file from the links above (any of them)?

thanks!

Forgiveness answered 3/7, 2014 at 11:58 Comment(1)
Have a look at these? codeproject.com/Tips/761490/… msdn.microsoft.com/en-us/library/dn659730.aspxOilskin
G
13

If you replace the word redir with download in the url you get the raw file instead of the webpage i.e.

https://onedrive.live.com/download?resid=DBBC281099F4FE69%21646

Gibber answered 3/5, 2015 at 1:11 Comment(0)
P
5

Basically, you can't. Those links are links to the web content that shows the files you have shared. If your scenario doesn't mind asking the user to log in to OneDrive, then you can use the Live SDK to access these files.

To access your public folder from Live SDK, you need to either use Live SDK to get the folder-id for your public folder, or convert the IDs in the URL you copied into the format the Live SDK uses:

folder.<user-id>.<folder-resid>

Where is the part of before the !. In general you shouldn't construct an ID, since it's possible the IDs will change in the future, and instead you should retrieve the ID from the service. However, with the URL you pasted the ID would be:

folder.DBBC281099F4FE69.DBBC281099F4FE69!646

Which will allow you to call

https://apis.live.net:443/v5.0/folder.DBBC281099F4FE69.DBBC281099F4FE69!646/files?access_token=<valid_token>

and retrieve the IDs for the individual files, which you can then download via Live SDK following these details: http://msdn.microsoft.com/en-US/library/dn659726.aspx#download_a_file

Peal answered 8/7, 2014 at 4:49 Comment(0)
L
2

For those who are still looking for a response to that question. The easiest way to find the file path is to go to One Drive on the web and right-click on the file that we want and select Embed. Τhen on the right we see the info window to integrate our file into a page. Inside the iframe is the source of the file. Then we have to replace the word embed with the word download and that's it.

Latten answered 11/3, 2018 at 18:4 Comment(0)
Y
0

Try something like this

  //we first need the file id
  string id = string.Empty;
  //we need to get all of the filenames stored in the root of the skydrive account
  LiveOperationResult result = await this.client.GetAsync("me/skydrive/files");

  //lets make a list of all these filenames
  List<object> items = result.Result["data"] as List<object>;

  //for every filename, check if it is what we want, in this case "sample.txt"
  //if it is what we want, get the id and save it to out already defined id value
  foreach (object item in items)
  {
      IDictionary<string, object> file = item as IDictionary<string, object>;
      if (file["name"].ToString() == "sample.txt")
      {
            id = file["id"].ToString();
      }
  }

  //to download the file we need to use the id + "/content"
  LiveDownloadOperationResult result2 = await client.DownloadAsync(string.Format("{0}/content", id));

  //once the file had downloaded, lets copy it to IsolatedStorage
 Stream stream = result2.Stream;
 using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
 {
     using (IsolatedStorageFileStream fileToSave = storage.OpenFile("sample.txt", FileMode.Create, FileAccess.ReadWrite))
     {
            stream.CopyTo(fileToSave);
            stream.Flush();
            stream.Close();
     }
}

here client is the object of LiveConnectClient class. Import

using Microsoft.Live;
using Microsoft.Live.Controls;

Here is use txt file as an example. Go through this example:http://www.baileystein.com/2013/10/20/skydrive-how-to-upload-and-download-a-text-file-on-wp8/

Yaroslavl answered 8/7, 2014 at 5:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.