Answered by:
Accessing the contents of a Skydrive text file using JavaScript

Question
-
Hello there
I am trying to obtain the contents of a text file from SkyDrive using JavaScript and the following code:
WL.api({
path: sPath + "/content"
},
function (response) {
if (response.error) {
HandleErrorResponse(response.error);
fnFollow(null);
}
else {
fnFollow(response.location);
}
});
}This is following the advice at http://msdn.microsoft.com/en-us/windowslive/hh561740.
Where sPath is the id of the folder (e.g. "file.41eee51f586e62bc.41EEE51F586E62BC!263").
In my callback function, response.location (the only property of response), is set to:How do I translate this value into the actual contents of the file?
Many thanks
Geoff Olding
Tuesday, January 17, 2012 4:32 PM
Answers
-
Hi Geoff,
I was able to do this using WinJS.xhr. I do not know enough about the SkyDrive API to help you there.
I simply used the .source property of the SkyDrive element:
WinJS.xhr({ url: file.source }). then(onTextFile); function onTextFile(result) { var a = result.resposeText; }
The result object is the response object.-Jeff
Jeff Sanders (MSFT)- Proposed as answer by Jeff SandersMicrosoft employee, Moderator Friday, January 20, 2012 4:00 PM
- Marked as answer by Geoff_Olding Sunday, January 22, 2012 7:26 PM
Friday, January 20, 2012 4:00 PMModerator
All replies
-
Hi Geoff,
http://msdn.microsoft.com/en-us/windowslive/hh561740#downloading_files
Has a section on how to do this in Metro style apps with the file picker. Did you try that code?
-Jeff
Jeff Sanders (MSFT)- Proposed as answer by Jeff SandersMicrosoft employee, Moderator Tuesday, January 17, 2012 5:01 PM
Tuesday, January 17, 2012 5:01 PMModerator -
Hi Jeff
Thanks for your quick reply. The code you reference is downloading a Skydrive file to a local file, based on a file location selected by the user. This is not what I want to do - I want to be able to get the contents of the Skydrive file (as a string), without having to save the file locally (which is a waste of time).
I guess I could try to adapt the example code (downloading to a local file without user intervention), however I would need to work out how I create an appropriate "file" object.
Many thanks
Geoff Olding
Tuesday, January 17, 2012 5:57 PM -
I got you. That really is not a Metro style app question. You should ask the Live SDK forums: http://social.msdn.microsoft.com/Forums/en-US/messengerconnect/threads
I am sure someone has wanted to so this in JavaScript before. Also I have not watch this yet but you may get some hints from this Build Talk: http://channel9.msdn.com/Events/BUILD/BUILD2011/PLAT-134C
-Jeff
Jeff Sanders (MSFT)- Proposed as answer by Jeff SandersMicrosoft employee, Moderator Tuesday, January 17, 2012 7:00 PM
Tuesday, January 17, 2012 7:00 PMModerator -
Hi Geoff,
I was able to do this using WinJS.xhr. I do not know enough about the SkyDrive API to help you there.
I simply used the .source property of the SkyDrive element:
WinJS.xhr({ url: file.source }). then(onTextFile); function onTextFile(result) { var a = result.resposeText; }
The result object is the response object.-Jeff
Jeff Sanders (MSFT)- Proposed as answer by Jeff SandersMicrosoft employee, Moderator Friday, January 20, 2012 4:00 PM
- Marked as answer by Geoff_Olding Sunday, January 22, 2012 7:26 PM
Friday, January 20, 2012 4:00 PMModerator -
Hello there
You are a star!
N.B. The SjyDrive API documentation in this respect is very unclear.
Regards
Geoff Olding
Sunday, January 22, 2012 7:26 PM