title: Upload file from Android application to Microsoft OneDrive with Xamarin and C#
body: <p>How can I upload file to OneDrive (SkyDrive) with Xamarin for Android?</p>
  
  <p>I have information about <a href="http://msdn.microsoft.com/en-us/library/dn659727.aspx" rel="nofollow">Downloading and uploading files on OneDrive (Android)</a></p>
  
  <p>Can I use Microsoft.Live in Xamarin Studio?
  I use it in Visual Studio for Windows Phone app:</p>
  
  <p>C#:</p>
  
  <pre><code>    private void skydrive_SessionChanged(object sender, LiveConnectSessionChangedEventArgs e)
      {
          if (e != null &amp;&amp; e.Status == LiveConnectSessionStatus.Connected)
          {
              this.client = new LiveConnectClient(e.Session);
              this.GetAccountInformations();
          }
          else
          {
              this.client = null;
              InfoText.Text = e.Error != null ? e.Error.ToString() : string.Empty;
          }
      }
  
      private async void GetAccountInformations()
      {
          try
          {
              LiveOperationResult operationResult = await this.client.GetAsync("me");
              var jsonResult = operationResult.Result as dynamic;
              string firstName = jsonResult.first_name ?? string.Empty;
              string lastName = jsonResult.last_name ?? string.Empty;  
              InfoText.Text = "Welcome " + firstName + " " + lastName;
          }
          catch (Exception e)
          {
              InfoText.Text = e.ToString();
          }
      }
  
      private async void btnUpload_Click(object sender, RoutedEventArgs e)
      {
          using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
          {
              using (var fileStream = store.OpenFile(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
              {
                  try
                  {
                      LiveOperationResult res = await client.BackgroundUploadAsync("me/skydrive",
                                                                                  new Uri("/shared/transfers/" + fileName, UriKind.Relative),
                                                                                  OverwriteOption.Overwrite
                                                                                  );
                      InfoText.Text = "File " + fileName + " uploaded";
                  }
                  catch (Exception ex)
                  {
  
                  }
              }
          }
      }
  </code></pre>
  
  <p>XAML:</p>
  
  <pre><code> &lt;Controls:SignInButton Canvas.Left="10" Canvas.Top="351" Content="Button" 
                                             Name="skydrive" Scopes="wl.basic wl.signin wl.offline_access wl.skydrive_update" 
                                             SessionChanged="skydrive_SessionChanged" 
                                             ClientId="00000000########"/&gt;
   &lt;TextBlock Name="InfoText" Width="167" Height="42" Canvas.Left="192" Canvas.Top="367"&gt;&lt;/TextBlock&gt;
   &lt;Button Name="btnUpload" Canvas.Left="10" Canvas.Top="430" Width="166"  Click="btnUpload_Click"&gt;Upload&lt;/Button&gt;
  </code></pre>
  
  <p>Are there other ways to upload file from Android app to other server?
  P.S. I can't use Visual Studio to create Android app, only Xamarin Studio.</p>