Step1: App.Xaml.cs
Step2: BlobStorageService.cs & Don't Forget to add nuget package(WindowsAzure.Storage)
Step3:MainPage.xaml
Step4:MainPage.Xaml.cs
Step5:PhotoModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using Xamarin.Forms; | |
namespace mylovee | |
{ | |
public partial class App : Application | |
{ | |
public App () | |
{ | |
InitializeComponent(); | |
MainPage = new NavigationPage(new MainPage()); | |
} | |
protected override void OnStart () | |
{ | |
// Handle when your app starts | |
} | |
protected override void OnSleep () | |
{ | |
// Handle when your app sleeps | |
} | |
protected override void OnResume () | |
{ | |
// Handle when your app resumes | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.WindowsAzure.Storage; | |
using Microsoft.WindowsAzure.Storage.Blob; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace (PleaseAddYourProjectNameSpace) | |
{ | |
public class BlobStorageService | |
{ | |
readonly static CloudStorageAccount _cloudStorageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=samir;AccountKey=xGedI/E6fPRLs2qXEicRbX48qbi1XTEc0XFjWac8wrLUhFAZ8GduGjrHEDcj2zuwmQGleaZEn5f3OUQ7dIg3Og==;EndpointSuffix=core.windows.net"); | |
readonly static CloudBlobClient _blobClient = _cloudStorageAccount.CreateCloudBlobClient(); | |
public static async Task<List<T>> GetBlobs<T>(string containerName, string prefix = "", int? maxresultsPerQuery = null, BlobListingDetails blobListingDetails = BlobListingDetails.None) where T : ICloudBlob | |
{ | |
var blobContainer = _blobClient.GetContainerReference(containerName); | |
var blobList = new List<T>(); | |
BlobContinuationToken continuationToken = null; | |
try | |
{ | |
do | |
{ | |
var response = await blobContainer.ListBlobsSegmentedAsync(prefix, true, blobListingDetails, maxresultsPerQuery, continuationToken, null, null); | |
continuationToken = response?.ContinuationToken; | |
foreach (var blob in response?.Results?.OfType<T>()) | |
{ | |
blobList.Add(blob); | |
} | |
} while (continuationToken != null); | |
} | |
catch (Exception e) | |
{ | |
//Handle Exception | |
} | |
return blobList; | |
} | |
public static async Task<CloudBlockBlob> SaveBlockBlob(string containerName, byte[] blob, string blobTitle) | |
{ | |
var blobContainer = _blobClient.GetContainerReference(containerName); | |
var blockBlob = blobContainer.GetBlockBlobReference(blobTitle); | |
await blockBlob.UploadFromByteArrayAsync(blob, 0, blob.Length); | |
return blockBlob; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8" ?> | |
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" | |
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | |
xmlns:local="clr-namespace:YourNameSpace" | |
x:Class="YourNameSpace.MainPage" | |
Title="MyBlobStoragePage"> | |
<StackLayout HorizontalOptions="Center" VerticalOptions="Center"> | |
<Label x:Name= "mytitle" HorizontalOptions="Center" VerticalOptions="Center"/> | |
<Image x:Name="myimage" HorizontalOptions="Center" VerticalOptions="Center"/> | |
<ActivityIndicator x:Name="myindicator"/> | |
</StackLayout> | |
</ContentPage> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.WindowsAzure.Storage.Blob; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using Xamarin.Forms; | |
namespace mylovee | |
{ | |
public partial class MainPage : ContentPage | |
{ | |
public MainPage() | |
{ | |
InitializeComponent(); | |
} | |
protected override async void OnAppearing() | |
{ | |
base.OnAppearing(); | |
myindicator.IsRunning = true; | |
var blobList = await BlobStorageService.GetBlobs<CloudBlockBlob>("photos"); | |
var firstBlob = blobList?.FirstOrDefault(); | |
var photo = new PhotoModel { Title = firstBlob?.Name, Uri = firstBlob?.Uri }; | |
mytitle.Text = photo?.Title; | |
myimage.Source = ImageSource.FromUri(photo?.Uri); | |
myindicator.IsRunning = false; | |
myindicator.IsVisible = false; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Text; | |
namespace (YourNameSpace) | |
{ | |
public class PhotoModel | |
{ | |
public System.Uri Uri { get; set; } | |
public string Title { get; set; } | |
} | |
} |