如何在Windows Phone App中浏览和上传文件

时间:2015-02-23 05:45:47

标签: c# xaml windows-phone-7 windows-phone-8 file-upload

如何在Windows手机中上传文件我的意思是哪些控件用于浏览文件(手机内容)是为Windows手机预定义的,还是我们需要手动创建。浏览它们并上传它们。

1 个答案:

答案 0 :(得分:2)

您可以尝试MSDN方式

  1. 确保用户已同意所需范围,然后创建上传
  2. 在应用重新启动时处理待处理的上传内容。
  3. private async void Upload()
    {
        try
        {
            // Ensure that the user has consented to the wl.skydrive and wl.skydrive_update scopes.
            var authClient = new LiveAuthClient();
            var authResult = await authClient.LoginAsync(new string[] { "wl.skydrive", "wl.skydrive_update" });
            if (authResult.Session != null)
            {
                var liveConnectClient = new LiveConnectClient(authResult.Session);
    
                // Upload to OneDrive.
                LiveUploadOperation uploadOperation = await liveConnectClient.CreateBackgroundUploadAsync(
                    uploadPath, fileName, uploadInputStream, OverwriteOption.Rename);
                LiveOperationResult uploadResult = await uploadOperation.StartAsync();
                HandleUploadResult(uploadResult);
            }
        }
        catch (LiveAuthException ex)
        {
            // Handle errors.
        }
        catch(LiveConnectException ex)
        {
            // Handle errors.
        }
    }
    
    
    
    
    var pendingOperations = await LiveConnectClient.GetCurrentBackgroundUploadsAsync();
    foreach(LiveDownloadOperation pendingOperation in pendingOperations)
    {
        try
        {
            var opResult = await pendingOperation.AttachAsync();
            // Handle results.
        }
        catch
        {
            // Handle errors.
        }
    }