简体   繁体   English

使用Xamarin和C#将文件从Android应用程序上传到Microsoft OneDrive

[英]Upload file from Android application to Microsoft OneDrive with Xamarin and C#

How can I upload file to OneDrive (SkyDrive) with Xamarin for Android? 如何使用Xamarin for Android将文件上传到OneDrive(SkyDrive)?

I have information about Downloading and uploading files on OneDrive (Android) 我了解有关在OneDrive(Android)上下载和上传文件的信息

Can I use Microsoft.Live in Xamarin Studio? 我可以在Xamarin Studio中使用Microsoft.Live吗? I use it in Visual Studio for Windows Phone app: 我在Visual Studio for Windows Phone应用程序中使用它:

C#: C#:

    private void skydrive_SessionChanged(object sender, LiveConnectSessionChangedEventArgs e)
    {
        if (e != null && 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)
                {

                }
            }
        }
    }

XAML: XAML:

 <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########"/>
 <TextBlock Name="InfoText" Width="167" Height="42" Canvas.Left="192" Canvas.Top="367"></TextBlock>
 <Button Name="btnUpload" Canvas.Left="10" Canvas.Top="430" Width="166"  Click="btnUpload_Click">Upload</Button>

Are there other ways to upload file from Android app to other server? 还有其他方法可以将文件从Android应用上传到其他服务器吗? PS I can't use Visual Studio to create Android app, only Xamarin Studio. PS我不能使用Visual Studio创建Android应用程序,只能使用Xamarin Studio。

You can use OneDrive for Android by creating and referencing Xamarin binding library. 您可以通过创建和引用Xamarin绑定库来使用OneDrive for Android。 It allows you to create a binding project that automatically wraps the .jar library with C# wrappers based on a declarative approach. 它允许您创建一个绑定项目,该项目基于声明性方法使用C#包装器自动包装.jar库。

Here is official manual 这是官方手册

And here is a link to Xamarin forums with existing binding library project and examples 这是带有现有绑定库项目和示例的Xamarin论坛链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Microsoft Graph:将文件从URL [C#]上传到onedrive - Microsoft Graph: upload files to onedrive from URL [C#] 使用 Microsoft Graph 将 C# Asp.Net Core 中的文件上传到 Sharepoint/OneDrive,无需用户交互 - Upload a file in C# Asp.Net Core to Sharepoint/OneDrive using Microsoft Graph without user interaction 使用 Microsoft Graph 将新文件上传到 onedrive c# asp.net - Upload new file to onedrive using microsoft graph c# asp.net 如何在 c# 中使用 Microsoft Graph Api 上传到 OneDrive - How to upload to OneDrive using Microsoft Graph Api in c# 以编程方式从C#创建文件到Onedrive? - Create file to Onedrive programmatically from C#? 在 c# 中使用来自 onedrive 的 Excel 文件 - Using an Excel file from onedrive in c# 将图像从Android上传到Xamarin C#中的php服务器 - Upload image from android to php server in Xamarin C# 从OneDrive获取文件,并将XML文件的数据使用到C#应用程序中 - Get a file from OneDrive and use data of xml file into C# application C# Winforms 使用 Microsoft Onedrive 进行身份验证 - C# Winforms Authenticate with Microsoft Onedrive 使用 Microsoft Graph API 将文件上传到 MVC 应用程序中的 onedrive,权限错误 - Using Microsoft Graph API to upload file to onedrive in MVC Application, Error with permissions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM