本文整理汇总了C#中Microsoft.Live.LiveConnectClient.CreateBackgroundUploadAsync方法的典型用法代码示例。如果您正苦于以下问题:C# LiveConnectClient.CreateBackgroundUploadAsync方法的具体用法?C# LiveConnectClient.CreateBackgroundUploadAsync怎么用?C# LiveConnectClient.CreateBackgroundUploadAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Live.LiveConnectClient
的用法示例。
在下文中一共展示了LiveConnectClient.CreateBackgroundUploadAsync方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: uploadButton_Click
private async void uploadButton_Click(object sender, RoutedEventArgs e)//上传
{
try
{
msgText.Text = "亲:正在上传";
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);
StorageFolder localFolder = ApplicationData.Current.LocalFolder;
StorageFile file = await localFolder.GetFileAsync(App.WordBookFileName);
String fileText = await FileIO.ReadTextAsync(file);
LiveUploadOperation uploadOperation = await liveConnectClient.CreateBackgroundUploadAsync(
"me/skydrive", file.Name, file, OverwriteOption.Overwrite);
LiveOperationResult uploadResult = await uploadOperation.StartAsync();
if (uploadResult.Result != null)
{
msgText.Text = "恭喜:您已成功同步生词至OneDrive!";
}
}
}
catch (LiveAuthException ex)
{
msgText.Text = ex.Message;
}
catch (LiveConnectException ex)
{
msgText.Text = ex.Message;
}
}
示例2: RunButton_Click
private async void RunButton_Click(object sender, RoutedEventArgs e)
{
string message = null;
try
{
// Ensure that the user has consented 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)
{
throw new InvalidOperationException("You need to sign in and give consent to the app.");
}
var liveConnectClient = new LiveConnectClient(authResult.Session);
// Validate parameters
var imageSourceUrl = imgSourceUrlTextBox.Text;
if (string.IsNullOrWhiteSpace(imageSourceUrl))
{
throw new InvalidOperationException("Image Url is empty.");
}
var uploadPath = uploadPathTextBox.Text;
if (string.IsNullOrWhiteSpace(uploadPath))
{
throw new InvalidOperationException("Upload location is empty.");
}
// Download the image from the Internet
var networkFileDownloader = new BackgroundDownloader();
DownloadOperation networkFileDownloadOperation = networkFileDownloader.CreateDownload(new Uri(imageSourceUrl), null);
await networkFileDownloadOperation.StartAsync();
IInputStream uploadInputStream = networkFileDownloadOperation.GetResultStreamAt(0);
// Upload to OneDrive
LiveUploadOperation uploadOperation = await liveConnectClient.CreateBackgroundUploadAsync(uploadPath, "ImageFromInternet.jpg", uploadInputStream, OverwriteOption.Rename);
LiveOperationResult uploadResult = await uploadOperation.StartAsync();
dynamic uploadedResource = uploadResult.Result;
string uploadedResourceId = uploadedResource.id;
string uploadedResourceName = uploadedResource.name;
string uploadedResourceLink = uploadedResource.source;
uploadedResourceTextBox.Text = string.Format("{0}\r\n{1}\r\n{2}", uploadedResourceId, uploadedResourceName, uploadedResourceLink);
// Download from the OneDrive
LiveDownloadOperation downloadOperation = await liveConnectClient.CreateBackgroundDownloadAsync(uploadedResourceId + "/content");
LiveDownloadOperationResult downloadResult = await downloadOperation.StartAsync();
if (downloadResult != null && downloadResult.Stream != null)
{
using (IRandomAccessStream ras = await downloadResult.GetRandomAccessStreamAsync())
{
BitmapImage imgSource = new BitmapImage();
imgSource.SetSource(ras);
skydriveImage.Source = imgSource;
}
}
}
catch (Exception ex)
{
message = "Operation failed: " + ex.Message;
}
if (message != null)
{
var dialog = new Windows.UI.Popups.MessageDialog(message);
await dialog.ShowAsync();
}
}
示例3: uploadToOnedriveButton_Click
private async void uploadToOnedriveButton_Click(object sender, RoutedEventArgs e)
{
try
{
if (loginResult.Session != null)
{
var liveConnectClient = new LiveConnectClient(loginResult.Session);
String uploadPath = "me/skydrive";
StorageFile getfile = await ApplicationData.Current.LocalFolder.GetFileAsync("MoneyNote.db");
// Upload to OneDrive. //uploadpath, fileName, uploadinputstream. overriteoption
LiveUploadOperation uploadOperation = await liveConnectClient.CreateBackgroundUploadAsync(
uploadPath, "MoneyNote.db", getfile, OverwriteOption.Overwrite);
LiveOperationResult uploadResult = await uploadOperation.StartAsync();
messagePrint(true, "upload");
}
}
catch (LiveAuthException ex)
{
// Handle errors.
ex.Message.ToString();
messagePrint(false, "upload");
}
catch (LiveConnectException ex)
{
// Handle errors.
ex.Message.ToString();
messagePrint(false, "upload");
}
catch (Exception ex)
{
// Handle Error.
ex.Message.ToString();
messagePrint(false, "upload");
}
}