【问题标题】:how to browse and upload files in Windows Phone App如何在 Windows Phone App 中浏览和上传文件
【发布时间】:2015-04-24 09:47:57
【问题描述】:
如何在 windows phone 中上传文件我的意思是哪些控件用于浏览文件(手机内容)是为 windows phone 预定义的还是我们需要手动创建的。浏览它们并上传它们。
【问题讨论】:
标签:
c#
xaml
windows-phone-7
windows-phone-8
file-upload
【解决方案1】:
你可以试试MSDN的方式
- 确保用户已同意所需范围,然后创建上传
- 在应用重新启动时处理挂起的上传。
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.
}
}