none
REST API for SkyDrive non-photo files, like .docx

    Question

  • Folder object is defined as "A user's folder in SkyDrive. Folders can contain combinations of photos, videos, and subfolders."

    I can put any files to my SkyDrive using web interface. Like, say, .docx. Is there really no way to read them via REST API?

    What API can I use to achieve it? Is it possible at all, and specifically from Windows Phone 7.1?

    Thank you!

    Tuesday, October 25, 2011 11:15 AM

Answers

  • Hello Igor,

    you can try the Connect Developer Preview which includes this possibilities you talk about out of the box. One thing to remember is - you are not allowed to use it for production, only for testing:

    http://connect.microsoft.com/site1226

    There is an excellent example, the SkyPad example, which you can adapt for phone:

    http://code.msdn.microsoft.com/windowsapps/Skypad-SkyDrive-Sample-8a187bd8

    There you can take a look at the source file for the main window. They create new

    text files on skydrive, list folders and much more.

    Hope this helps.

     Here is also a code sample, in which I have adapted the download of the user image, user name from the SkyPad sample to WP7 Mango. For usual .NET applications, not WinRT, the effort should be even smaller:

     

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using Microsoft.Phone.Controls;
    using Microsoft.Phone.Shell;
    using System.Windows.Navigation;
    using Microsoft.Live;
    using Microsoft.Live.Controls;
    using System.IO; 
    
    
    
    namespace MetroFreeLancer
    {
        using System.Windows.Media.Imaging;
    
        public partial class MainPage : PhoneApplicationPage
        {
            // Constructor
            public MainPage()
            {
                InitializeComponent();
    
                // Set the data context of the listbox control to the sample data
                DataContext = App.ViewModel;
                this.Loaded +=new RoutedEventHandler(MainPage_Loaded);
    			
    			//init the right app bar
    			IApplicationBar bar = (IApplicationBar) new ApplicationBar();
    			bar.IsVisible = false;
    			this.ApplicationBar = bar;
    			this.ApplicationBar = this.ApplicationBar = (IApplicationBar)App.Current.Resources["appbarChallanges"];
            }
    
            // Load data for the ViewModel Items
            private void MainPage_Loaded(object sender, RoutedEventArgs e)
            {
                if (!App.ViewModel.IsDataLoaded)
                {
                    App.ViewModel.LoadData();
                }
            }
    
            private void Panorama_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
            {
    			Panorama p = (Panorama) sender;
    			PanoramaItem pi =  p.SelectedItem as PanoramaItem;
            	
    			//Load individual menu
    			switch(pi.Name)
    			{
    				case  "challanges":
    					this.ApplicationBar = (IApplicationBar)App.Current.Resources["appbarChallanges"];
    					break;
    				case "hardwork":
    					this.ApplicationBar = (IApplicationBar)App.Current.Resources["appbarHardWork"];
    					break;
    				case "customers":
    					this.ApplicationBar = (IApplicationBar)App.Current.Resources["appbarCustomers"];
    					break;
    				case "invoicing":
    					this.ApplicationBar = (IApplicationBar)App.Current.Resources["appbarInvoicing"];
    					break;
    				case "dashboard":
    					this.ApplicationBar = (IApplicationBar)App.Current.Resources["appbarDashboard"];
    					break;
    				case "settings":
    					this.ApplicationBar = (IApplicationBar)App.Current.Resources["appbarSettings"];
    					break;
    			}
            }
    		
    		LiveConnectClient client;
    		
    		void btnSignin_SessionChanged(object sender, LiveConnectSessionChangedEventArgs e) 
    		{ 
    			if (e.Session != null && 
    				e.Session.Status == LiveConnectSessionStatus.Connected) 
    			{ 
                    
    				client = new LiveConnectClient(e.Session); 
    				
    				client.GetCompleted += 
    					new EventHandler<LiveOperationCompletedEventArgs>(btnSignin_GetCompleted); 
    				client.GetAsync("me", null); 
    			} 
    			else
    			{ 
    				this.imgUserPicture.Visibility = Visibility.Collapsed;
                    this.tblUserName.Visibility = Visibility.Collapsed;
    				client = null; 
    			} 
                
    		}
    		void btnSignin_GetCompleted(object sender, LiveOperationCompletedEventArgs e)
    		{
    		    client.GetCompleted -= this.btnSignin_GetCompleted;
    			if (e.Error == null)
    			{
                    MessageBox.Show("Successfully logged in.", "Windows Live Message", MessageBoxButton.OK);
                    getUserPicture();
    			} 
    			else
    			{
                    MessageBox.Show(e.Error.Message, "Windows Live Error", MessageBoxButton.OK);
    			} 
    		}
    
    
            private void getUserName()
            {
                client.GetCompleted += new EventHandler<LiveOperationCompletedEventArgs>(getUserName_Callback);
                client.GetAsync("/me");
            } 
    
    
    		private void getUserPicture() 
            { 
                var memoryStream = new MemoryStream();
                client.DownloadCompleted += new EventHandler<LiveOperationCompletedEventArgs>(getUserPicture_Callback); 
                client.DownloadAsync("/me/picture?return_ssl_resources=true", memoryStream, memoryStream); 
            } 
    
    		
            private void getUserName_Callback(object sender, LiveOperationCompletedEventArgs e)
            {
                client.GetCompleted -= getUserName_Callback;
    
                if (e.Error == null)
                {
                    var user = e.Result;
                    tblUserName.Text = String.Format("Logged in as {0}.", user["name"].ToString());
                }
                else
                {
                    MessageBox.Show(e.Error.Message, "Windows Live Error", MessageBoxButton.OK);
                }
    
               
            } 
    		
    		  private void getUserPicture_Callback(object sender, LiveOperationCompletedEventArgs e) 
            { 
               client.DownloadCompleted -= getUserPicture_Callback; 
     
               if (e.Error == null) 
                { 
    				
                    MemoryStream imageStream = e.UserState as MemoryStream;
                    BitmapImage b = new BitmapImage();
                    b.SetSource(imageStream);
    
                    if (imageStream != null)
                    {
                        this.imgUserPicture.Source = b;
                        this.imgUserPicture.Visibility = Visibility.Visible;
                        this.tblUserName.Visibility = Visibility.Visible;
    
                    } 
                    else 
                    {
                        MessageBox.Show("Unable to find your picture.", "Windows Live Message", MessageBoxButton.OK);
                    } 
                } 
                else
               {
                   MessageBox.Show(e.Error.Message, "Windows Live Error", MessageBoxButton.OK);
               } 
     
                getUserName(); 
            } 
    
    
    		
        }
    }


    http://embdocumentinhalator.codeplex.com/
    Tuesday, October 25, 2011 5:05 PM

All replies

  • Hello Igor,

    you can try the Connect Developer Preview which includes this possibilities you talk about out of the box. One thing to remember is - you are not allowed to use it for production, only for testing:

    http://connect.microsoft.com/site1226

    There is an excellent example, the SkyPad example, which you can adapt for phone:

    http://code.msdn.microsoft.com/windowsapps/Skypad-SkyDrive-Sample-8a187bd8

    There you can take a look at the source file for the main window. They create new

    text files on skydrive, list folders and much more.

    Hope this helps.

     Here is also a code sample, in which I have adapted the download of the user image, user name from the SkyPad sample to WP7 Mango. For usual .NET applications, not WinRT, the effort should be even smaller:

     

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using Microsoft.Phone.Controls;
    using Microsoft.Phone.Shell;
    using System.Windows.Navigation;
    using Microsoft.Live;
    using Microsoft.Live.Controls;
    using System.IO; 
    
    
    
    namespace MetroFreeLancer
    {
        using System.Windows.Media.Imaging;
    
        public partial class MainPage : PhoneApplicationPage
        {
            // Constructor
            public MainPage()
            {
                InitializeComponent();
    
                // Set the data context of the listbox control to the sample data
                DataContext = App.ViewModel;
                this.Loaded +=new RoutedEventHandler(MainPage_Loaded);
    			
    			//init the right app bar
    			IApplicationBar bar = (IApplicationBar) new ApplicationBar();
    			bar.IsVisible = false;
    			this.ApplicationBar = bar;
    			this.ApplicationBar = this.ApplicationBar = (IApplicationBar)App.Current.Resources["appbarChallanges"];
            }
    
            // Load data for the ViewModel Items
            private void MainPage_Loaded(object sender, RoutedEventArgs e)
            {
                if (!App.ViewModel.IsDataLoaded)
                {
                    App.ViewModel.LoadData();
                }
            }
    
            private void Panorama_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
            {
    			Panorama p = (Panorama) sender;
    			PanoramaItem pi =  p.SelectedItem as PanoramaItem;
            	
    			//Load individual menu
    			switch(pi.Name)
    			{
    				case  "challanges":
    					this.ApplicationBar = (IApplicationBar)App.Current.Resources["appbarChallanges"];
    					break;
    				case "hardwork":
    					this.ApplicationBar = (IApplicationBar)App.Current.Resources["appbarHardWork"];
    					break;
    				case "customers":
    					this.ApplicationBar = (IApplicationBar)App.Current.Resources["appbarCustomers"];
    					break;
    				case "invoicing":
    					this.ApplicationBar = (IApplicationBar)App.Current.Resources["appbarInvoicing"];
    					break;
    				case "dashboard":
    					this.ApplicationBar = (IApplicationBar)App.Current.Resources["appbarDashboard"];
    					break;
    				case "settings":
    					this.ApplicationBar = (IApplicationBar)App.Current.Resources["appbarSettings"];
    					break;
    			}
            }
    		
    		LiveConnectClient client;
    		
    		void btnSignin_SessionChanged(object sender, LiveConnectSessionChangedEventArgs e) 
    		{ 
    			if (e.Session != null && 
    				e.Session.Status == LiveConnectSessionStatus.Connected) 
    			{ 
                    
    				client = new LiveConnectClient(e.Session); 
    				
    				client.GetCompleted += 
    					new EventHandler<LiveOperationCompletedEventArgs>(btnSignin_GetCompleted); 
    				client.GetAsync("me", null); 
    			} 
    			else
    			{ 
    				this.imgUserPicture.Visibility = Visibility.Collapsed;
                    this.tblUserName.Visibility = Visibility.Collapsed;
    				client = null; 
    			} 
                
    		}
    		void btnSignin_GetCompleted(object sender, LiveOperationCompletedEventArgs e)
    		{
    		    client.GetCompleted -= this.btnSignin_GetCompleted;
    			if (e.Error == null)
    			{
                    MessageBox.Show("Successfully logged in.", "Windows Live Message", MessageBoxButton.OK);
                    getUserPicture();
    			} 
    			else
    			{
                    MessageBox.Show(e.Error.Message, "Windows Live Error", MessageBoxButton.OK);
    			} 
    		}
    
    
            private void getUserName()
            {
                client.GetCompleted += new EventHandler<LiveOperationCompletedEventArgs>(getUserName_Callback);
                client.GetAsync("/me");
            } 
    
    
    		private void getUserPicture() 
            { 
                var memoryStream = new MemoryStream();
                client.DownloadCompleted += new EventHandler<LiveOperationCompletedEventArgs>(getUserPicture_Callback); 
                client.DownloadAsync("/me/picture?return_ssl_resources=true", memoryStream, memoryStream); 
            } 
    
    		
            private void getUserName_Callback(object sender, LiveOperationCompletedEventArgs e)
            {
                client.GetCompleted -= getUserName_Callback;
    
                if (e.Error == null)
                {
                    var user = e.Result;
                    tblUserName.Text = String.Format("Logged in as {0}.", user["name"].ToString());
                }
                else
                {
                    MessageBox.Show(e.Error.Message, "Windows Live Error", MessageBoxButton.OK);
                }
    
               
            } 
    		
    		  private void getUserPicture_Callback(object sender, LiveOperationCompletedEventArgs e) 
            { 
               client.DownloadCompleted -= getUserPicture_Callback; 
     
               if (e.Error == null) 
                { 
    				
                    MemoryStream imageStream = e.UserState as MemoryStream;
                    BitmapImage b = new BitmapImage();
                    b.SetSource(imageStream);
    
                    if (imageStream != null)
                    {
                        this.imgUserPicture.Source = b;
                        this.imgUserPicture.Visibility = Visibility.Visible;
                        this.tblUserName.Visibility = Visibility.Visible;
    
                    } 
                    else 
                    {
                        MessageBox.Show("Unable to find your picture.", "Windows Live Message", MessageBoxButton.OK);
                    } 
                } 
                else
               {
                   MessageBox.Show(e.Error.Message, "Windows Live Error", MessageBoxButton.OK);
               } 
     
                getUserName(); 
            } 
    
    
    		
        }
    }


    http://embdocumentinhalator.codeplex.com/
    Tuesday, October 25, 2011 5:05 PM
  • Hi Igor,

    I have implemented a complete sample, imitation the SkyPad sample on Windows Phone (not complete). Your can save a file and download the same file you created.

    The sample can be dowloaded here:

    SkyPad on WP7

    Regards,

    Ilija

     


    http://embdocumentinhalator.codeplex.com/
    • Edited by Ilija Injac Sunday, October 30, 2011 11:43 PM UPDATED LINK TO BLOG
    Wednesday, October 26, 2011 9:46 AM
  • Great, thank you!


    Loved your comments in sample.

    Wednesday, October 26, 2011 1:20 PM