locked
Saving a Text File on SkyDrive in a Metro Style app using JavaScript

    Question

  • Hello there

    I am writing a Metro Style app using JavaScript and the Skydrive API.

    I want to create (and subsequently update) the content of a text file on a Skydrive folder, based on the contents of a string. 
    I do not want to upload a file (unless this is the only workaround), and do not want the user to pick the file to upload.

    I am trying to follow the documentation at http://msdn.microsoft.com/en-us/windowslive/hh561740, which doesn't provide a clear example.  Can somebody please provide some example code on how to do this.

    Many thanks

    Geoff Olding

    Thursday, March 22, 2012 10:21 PM

Answers

All replies

  • I am unaware of a complete sample however you should be able to get what you need by doing the following.

    I suggest you start with this sample in HTML5/Javascript:

    http://code.msdn.microsoft.com/windowsapps/Live-SDK-Windows-Developer-8ad35141

    This will give you the knowledge necessary to access auth and the SDK calls in Javascript.

    Then take a look at this sample in C# - http://code.msdn.microsoft.com/windowsapps/Skypad-SkyDrive-Sample-8a187bd8 - whick will give you a clue whick WL api calls to make.

    -Jeff


    Jeff Sanders (MSFT)

    Tuesday, March 27, 2012 1:21 PM
    Moderator
  • PS, see the Live SDK site for examples doing exactly what you want in Metro html5/javascript apps:

    http://msdn.microsoft.com/en-us/live/hh561740.aspx#uploading_files

    -Jeff


    Jeff Sanders (MSFT)

    Tuesday, March 27, 2012 1:30 PM
    Moderator
  • Thanks for your reply, however I an unclear why I am being refered back to the same documentation that I mentioned in my original post.

    This documentation does not provide a clear example of how to update the content of a Skydrive file based on the contents of a string.

    Wednesday, March 28, 2012 10:35 PM
  • Thanks for your reply, however these sites do not provide me with the information I need.

    The first sample (http://code.msdn.microsoft.com/windowsapps/Live-SDK-Windows-Developer-8ad35141) does not update any of the files, whilst the second sample ( http://code.msdn.microsoft.com/windowsapps/Skypad-SkyDrive-Sample-8a187bd8), shows you how to save the contents of a file using the C# library (using UploadAsync), which doesn't really help in trying to do the same thing using JavaScript.

    Regards

    Geoff Olding

    Wednesday, March 28, 2012 10:40 PM
  • Hi Geoff,

    No the links do not give you a specific code snippet however the APIs are similar between C# and JS and you should be able to extract what you need from that documentation.  If you are not able to, you can ping the Live SDK forum to see if someone there can provide you a specific code snippet to do exactly what you want.

    Most of the struggle people have with the Live SDK is simply understanding the API and that is fairly language independant.  Did my 2nd post not contain what you want?

    -Jeff


    Jeff Sanders (MSFT)


    Thursday, March 29, 2012 1:42 PM
    Moderator
  • Hi Jeff

    I must say I disagree with your comments, as follows:

    1) “however the APIs are similar between C# and JS” – really?  In another post that I made, (http://social.msdn.microsoft.com/Forums/en-US/winappswithhtml5/thread/08236192-0319-4499-95d7-25e9565185b7/), you kindly provided me with the way to undertake another standard bit of Skydrive related functionality that is not properly documented, i.e. how to download the content of a Skydrive file.  This is my code in JavaScript:

            WinJS.xhr({ url: oFile.source }).
            then(function (oResult) {
                try {
                    var sText = oResult.responseText;

    The Skypad example is in C# and is as follows:

    Client.DownloadAsync(noteId + “/content?return_ssl_resources=true”);

    The similarity of these two APIs in this respect is not entirely obvious to me.

    I now have the task of taking the following C# code for saving the contents of a text file (from the Skypad example), and turning this into JavaScript:

    Client.UploadAsync(folderIds.Peek(), filename, true, stream, stream);

    You seem to be implying that I should be able to do that – perhaps you could elaborate further.

    2) “Most of the struggle people have with the Live SDK is simply understanding the API and that is fairly language independant”
    I have not found understanding the API difficult for the most part – you can simply follow the examples.  In my view the documentation is pretty good, however is not complete, and fulls short of providing some proper examples, in JavaScript at least, of some fairly basic things that developers are going to want to do.  I am unclear why my comments do not appear to be being used to improve the quality of this documentation.

    Have I misunderstood something?

    Regards

    Geoff Olding

    Thursday, March 29, 2012 3:33 PM
  • Hi Geoff,

    The SkyDrive API is not unique to Metro style app programming.  I suggest you post further queries to the SkyDrive Forums where you can get assistance from people that regularly use this SDK and where engineers familair with the SDK are assisting people.  I would need to do the same research you would as I do not have any special knowledge of this SDK.

    That said, I will try and carve out some time to play with this SDK and see if I am able to create a simple sample!  It may not be today but perhaps tomorrow?  I will do my best.

    -Jeff


    Jeff Sanders (MSFT)

    Thursday, March 29, 2012 5:28 PM
    Moderator
  • Geoff,

    I could not find a way to do what you are trying to do with SkyDrive APIs but again, they SkyDrive Forums is the place to engage SkyDrive experts.  It looks like you will have to read the file and append the data then save it back to SkyDrive.  I could not find a way to append to a file that is already up there.

    -Jeff


    Jeff Sanders (MSFT)

    Friday, March 30, 2012 1:40 PM
    Moderator
  • Hi Jeff

    I have an open post on the SkyDrive forums.

    I am trying to do what you suggest, however I am looking for a way to "save it back to SkyDrive", i.e. to update the content of a SkyDrive file based on a string.

    Tuesday, April 03, 2012 10:53 AM
  • I have now put in a workaround solution as per my post in the Live Connect forum (http://social.msdn.microsoft.com/Forums/uk-UA/messengerconnect/thread/68797819-a584-4433-bc81-826d3a7e8703?prof=required)
    Sunday, May 06, 2012 2:28 PM