コード例 #1
0
        private async void btnSave_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                btnSave.IsEnabled   = false;
                btnSave.Content     = "Uploading....";
                progress.Visibility = Visibility.Visible;
                // Source: https://azure.microsoft.com/en-us/documentation/articles/mobile-services-javascript-backend-windows-universal-dotnet-upload-data-blob-storage/#test
                // Part one: upload files to database
                // Create the connectionstring
                String StorageConnectionString = "DefaultEndpointsProtocol=https;AccountName=uonlife;AccountKey=LzU9gRoJgvtKtY7rIPE3w1Z7Toc39AfcBO+Y+Q4ZCYoZmXd2KTgpZ5muya6JkxaZRtNAo3ib3FTpw7gAncpOPA==";
                // Retrieve storage account from connection string.
                CloudStorageAccount storageAccount = CloudStorageAccount.Parse(StorageConnectionString);
                // Create the blob client.
                CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
                // Retrieve a reference to a container. (pictures)
                CloudBlobContainer container = blobClient.GetContainerReference(GlobalVariable.loginUser.ToLower());
                await container.CreateIfNotExistsAsync();

                string         sFileName             = recordProfile.ToString();
                CloudBlockBlob blobFromSASCredential =
                    container.GetBlockBlobReference(fileName);
                await blobFromSASCredential.UploadFromFileAsync(_recordStorageFile);

                MessageDialog msgbox = new MessageDialog("Upload success");
                await msgbox.ShowAsync();

                Frame.Navigate(typeof(MainPage));
            }
            catch (Exception ex)
            {
                MessageDialog msgbox = new MessageDialog("Error: " + ex.Message);
                await msgbox.ShowAsync();

                btnSave.IsEnabled   = true;
                btnSave.Content     = "Upload File To Cloud";
                progress.Visibility = Visibility.Collapsed;
            }
        }