SlideShare una empresa de Scribd logo
1 de 8
Descargar para leer sin conexión
UWP WITH MICROSOFT AZURE
BY ENG SOON CHEAH
1
UWP WITH MICROSOFT AZURE
UWP with Microsoft Azure
STORE IMAGE AND RETRIEVE IMAGE BY USING BLOB STORAGE
Pre-Requirement
1. Install Visual Studio 2015
2. Install Azure SDK
3. Microsoft Azure Account
Let Start to Code!
Click the NEW > DATA SERVICES > STORAGE > QUICK CREATE > fill in the information > Create storage
Account
2
UWP WITH MICROSOFT AZURE
After the account is created you will find the dashboard.
To access azure storage we have a storage account name and access keys.
Click on manage access keys at the bottom and you will find them as below.
We will now create a Windows UWP with the following UI. Add mobile services and azure storage
nuget package foe the app.
<Button x:Name="button" Content="Select Picture" HorizontalAlignment="Left" Margin="65,77,0,0"
VerticalAlignment="Top" Height="68" Width="221" Click="SelectPic_clicked" FontSize="26.667"/>
<Image x:Name="image" HorizontalAlignment="Left" Height="240" Margin="65,256,0,0"
VerticalAlignment="Top" Width="335"/>
3
UWP WITH MICROSOFT AZURE
In the button click event paste the following code,
private async void SelectPic_clicked(object sender, RoutedEventArgs e)
{
try
{
FileOpenPicker fop = new FileOpenPicker();
fop.FileTypeFilter.Add(".jpg");
fop.FileTypeFilter.Add(".jpeg");
fop.FileTypeFilter.Add(".png");
fop.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
StorageFile sf = await fop.PickSingleFileAsync();
IRandomAccessStream str = await sf.OpenAsync(FileAccessMode.Read);
CloudStorageAccount account;
CloudBlobClient blobClient;
CloudBlobContainer container;
account = new CloudStorageAccount(new StorageCredentials("Insert your account name", "Insert
your key"), true);
blobClient = account.CreateCloudBlobClient();
container = blobClient.GetContainerReference("pictures");
await container.CreateIfNotExistsAsync();
BlobContainerPermissions per = new BlobContainerPermissions();
per.PublicAccess = BlobContainerPublicAccessType.Blob;
await container.SetPermissionsAsync(per);
CloudBlockBlob blob = container.GetBlockBlobReference(sf.Name);
await blob.UploadFromFileAsync(sf);
BitmapImage bmp = new BitmapImage();
bmp.UriSource = blob.Uri;
BlobData imageData = new BlobData
{
imageUrl = blob.Uri.ToString(),
name = sf.Name
};
4
UWP WITH MICROSOFT AZURE
await App.MobileService.GetTable<BlobData>().InsertAsync(imageData);
var m1 = new MessageDialog("Image Uploaded").ShowAsync();
image.Source = bmp;
}
catch(Exception ex)
{
var m2 = new MessageDialog(ex.ToString()).ShowAsync();
}
In the above code I have used FileOpenPicker to select an image. And used Mobile service to store
blob name and url once uploaded.
Use your account name and account key. I have used the following code for class.
To retrieve images from the blob storage, I used mobile services to store the information. Use the
following code to make the UI.
Add the following is the c# code for retrieval of images.
public class BlobData
{
public string id { get; set; }
public string name { get; set; }
public string imageUrl { get;
set; }
}
<Button x:Name="button1" Content="Download Images" HorizontalAlignment="Left"
Margin="618,64,0,0" VerticalAlignment="Top" Height="81" Width="259" FontSize="26.667"
Click="Download_clicked"/>
<ListView x:Name="ImageList" HorizontalAlignment="Left" Height="483" Margin="659,184,0,0"
VerticalAlignment="Top" Width="496">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding name}" />
<Image Height="120" Width="150" Source="{Binding imageUrl}"/>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
List<BlobData> allImages = await
App.MobileService.GetTable<BlobData>().ToListAsync();
ImageList.ItemsSource = allImages;
5
UWP WITH MICROSOFT AZURE
Screenshot 1
Screenshot 2
Screenshot 3
6
UWP WITH MICROSOFT AZURE
Screenshot 4
Screenshot 5
7
UWP WITH MICROSOFT AZURE
References:
1. How to operate Azure Blob and Table Storage in Windows Store apps
https://code.msdn.microsoft.com/windowsapps/How-to-use-Windows-Azure-b3447051
2. Universal Windows Platform (UWP) App Development
https://channel9.msdn.com/Series/Windows-10-development-for-absolute-beginners

Más contenido relacionado

Destacado

67+68 M5C2 Lezione 5. dalla scuola del curricolo alla scuola dei piani di stu...
67+68 M5C2 Lezione 5. dalla scuola del curricolo alla scuola dei piani di stu...67+68 M5C2 Lezione 5. dalla scuola del curricolo alla scuola dei piani di stu...
67+68 M5C2 Lezione 5. dalla scuola del curricolo alla scuola dei piani di stu...raffaelebruno1
 
Using git in visual studio 2015
Using git in visual studio 2015Using git in visual studio 2015
Using git in visual studio 2015Cheah Eng Soon
 
67+68 M5C3 Lezione 5. il diritto all integrazione scolastica
67+68 M5C3 Lezione 5. il diritto all integrazione scolastica67+68 M5C3 Lezione 5. il diritto all integrazione scolastica
67+68 M5C3 Lezione 5. il diritto all integrazione scolasticaraffaelebruno1
 
Дайджест вакансий второй площадки ИТ-парка в г. Набережные Челны май 2013
Дайджест вакансий второй площадки ИТ-парка в г. Набережные Челны май 2013Дайджест вакансий второй площадки ИТ-парка в г. Набережные Челны май 2013
Дайджест вакансий второй площадки ИТ-парка в г. Набережные Челны май 2013itpark-kazan
 
Presentacion general supension plus 2015 2015 01 06
Presentacion general supension plus 2015 2015 01 06Presentacion general supension plus 2015 2015 01 06
Presentacion general supension plus 2015 2015 01 06Cano Asesor
 
2nd batxillerat general information
2nd batxillerat general information2nd batxillerat general information
2nd batxillerat general informationAmalio_Arnandis
 

Destacado (9)

67+68 M5C2 Lezione 5. dalla scuola del curricolo alla scuola dei piani di stu...
67+68 M5C2 Lezione 5. dalla scuola del curricolo alla scuola dei piani di stu...67+68 M5C2 Lezione 5. dalla scuola del curricolo alla scuola dei piani di stu...
67+68 M5C2 Lezione 5. dalla scuola del curricolo alla scuola dei piani di stu...
 
Using git in visual studio 2015
Using git in visual studio 2015Using git in visual studio 2015
Using git in visual studio 2015
 
Latest
LatestLatest
Latest
 
De donde vienen las ideas
De donde vienen las ideasDe donde vienen las ideas
De donde vienen las ideas
 
67+68 M5C3 Lezione 5. il diritto all integrazione scolastica
67+68 M5C3 Lezione 5. il diritto all integrazione scolastica67+68 M5C3 Lezione 5. il diritto all integrazione scolastica
67+68 M5C3 Lezione 5. il diritto all integrazione scolastica
 
Дайджест вакансий второй площадки ИТ-парка в г. Набережные Челны май 2013
Дайджест вакансий второй площадки ИТ-парка в г. Набережные Челны май 2013Дайджест вакансий второй площадки ИТ-парка в г. Набережные Челны май 2013
Дайджест вакансий второй площадки ИТ-парка в г. Набережные Челны май 2013
 
新土俵戦略2012
新土俵戦略2012新土俵戦略2012
新土俵戦略2012
 
Presentacion general supension plus 2015 2015 01 06
Presentacion general supension plus 2015 2015 01 06Presentacion general supension plus 2015 2015 01 06
Presentacion general supension plus 2015 2015 01 06
 
2nd batxillerat general information
2nd batxillerat general information2nd batxillerat general information
2nd batxillerat general information
 

Más de Cheah Eng Soon

Microsoft Defender for Endpoint
Microsoft Defender for EndpointMicrosoft Defender for Endpoint
Microsoft Defender for EndpointCheah Eng Soon
 
Azure Active Directory - Secure and Govern
Azure Active Directory - Secure and GovernAzure Active Directory - Secure and Govern
Azure Active Directory - Secure and GovernCheah Eng Soon
 
MEM for OnPrem Environments
MEM for OnPrem EnvironmentsMEM for OnPrem Environments
MEM for OnPrem EnvironmentsCheah Eng Soon
 
Microsoft Threat Protection Automated Incident Response
Microsoft Threat Protection Automated Incident Response Microsoft Threat Protection Automated Incident Response
Microsoft Threat Protection Automated Incident Response Cheah Eng Soon
 
Azure Penetration Testing
Azure Penetration TestingAzure Penetration Testing
Azure Penetration TestingCheah Eng Soon
 
Azure Penetration Testing
Azure Penetration TestingAzure Penetration Testing
Azure Penetration TestingCheah Eng Soon
 
Penetration Testing Azure for Ethical Hackers
Penetration Testing Azure for Ethical HackersPenetration Testing Azure for Ethical Hackers
Penetration Testing Azure for Ethical HackersCheah Eng Soon
 
Microsoft Threat Protection Automated Incident Response Demo
Microsoft Threat Protection Automated Incident Response DemoMicrosoft Threat Protection Automated Incident Response Demo
Microsoft Threat Protection Automated Incident Response DemoCheah Eng Soon
 
Microsoft Secure Score Demo
Microsoft Secure Score DemoMicrosoft Secure Score Demo
Microsoft Secure Score DemoCheah Eng Soon
 
Microsoft Cloud App Security Demo
Microsoft Cloud App Security DemoMicrosoft Cloud App Security Demo
Microsoft Cloud App Security DemoCheah Eng Soon
 
M365 Attack Simulation Demo
M365 Attack Simulation DemoM365 Attack Simulation Demo
M365 Attack Simulation DemoCheah Eng Soon
 
Azure Active Directory - External Identities Demo
Azure Active Directory - External Identities Demo Azure Active Directory - External Identities Demo
Azure Active Directory - External Identities Demo Cheah Eng Soon
 
Azure Weekend 2020 Build Malaysia Bus Uncle Chatbot
Azure Weekend 2020 Build Malaysia Bus Uncle ChatbotAzure Weekend 2020 Build Malaysia Bus Uncle Chatbot
Azure Weekend 2020 Build Malaysia Bus Uncle ChatbotCheah Eng Soon
 
Microsoft Azure的20大常见安全漏洞与配置错误
Microsoft Azure的20大常见安全漏洞与配置错误Microsoft Azure的20大常见安全漏洞与配置错误
Microsoft Azure的20大常见安全漏洞与配置错误Cheah Eng Soon
 
20 common security vulnerabilities and misconfiguration in Azure
20 common security vulnerabilities and misconfiguration in Azure20 common security vulnerabilities and misconfiguration in Azure
20 common security vulnerabilities and misconfiguration in AzureCheah Eng Soon
 
Integrate Microsoft Graph with Azure Bot Services
Integrate Microsoft Graph with Azure Bot ServicesIntegrate Microsoft Graph with Azure Bot Services
Integrate Microsoft Graph with Azure Bot ServicesCheah Eng Soon
 
Azure Sentinel with Office 365
Azure Sentinel with Office 365Azure Sentinel with Office 365
Azure Sentinel with Office 365Cheah Eng Soon
 

Más de Cheah Eng Soon (20)

Microsoft Defender for Endpoint
Microsoft Defender for EndpointMicrosoft Defender for Endpoint
Microsoft Defender for Endpoint
 
Azure Active Directory - Secure and Govern
Azure Active Directory - Secure and GovernAzure Active Directory - Secure and Govern
Azure Active Directory - Secure and Govern
 
Microsoft Zero Trust
Microsoft Zero TrustMicrosoft Zero Trust
Microsoft Zero Trust
 
MEM for OnPrem Environments
MEM for OnPrem EnvironmentsMEM for OnPrem Environments
MEM for OnPrem Environments
 
Microsoft Threat Protection Automated Incident Response
Microsoft Threat Protection Automated Incident Response Microsoft Threat Protection Automated Incident Response
Microsoft Threat Protection Automated Incident Response
 
Azure Penetration Testing
Azure Penetration TestingAzure Penetration Testing
Azure Penetration Testing
 
Azure Penetration Testing
Azure Penetration TestingAzure Penetration Testing
Azure Penetration Testing
 
Penetration Testing Azure for Ethical Hackers
Penetration Testing Azure for Ethical HackersPenetration Testing Azure for Ethical Hackers
Penetration Testing Azure for Ethical Hackers
 
Microsoft Threat Protection Automated Incident Response Demo
Microsoft Threat Protection Automated Incident Response DemoMicrosoft Threat Protection Automated Incident Response Demo
Microsoft Threat Protection Automated Incident Response Demo
 
Microsoft Secure Score Demo
Microsoft Secure Score DemoMicrosoft Secure Score Demo
Microsoft Secure Score Demo
 
Microsoft Cloud App Security Demo
Microsoft Cloud App Security DemoMicrosoft Cloud App Security Demo
Microsoft Cloud App Security Demo
 
M365 Attack Simulation Demo
M365 Attack Simulation DemoM365 Attack Simulation Demo
M365 Attack Simulation Demo
 
Cloud Security Demo
Cloud Security DemoCloud Security Demo
Cloud Security Demo
 
Azure Active Directory - External Identities Demo
Azure Active Directory - External Identities Demo Azure Active Directory - External Identities Demo
Azure Active Directory - External Identities Demo
 
Azure WAF
Azure WAFAzure WAF
Azure WAF
 
Azure Weekend 2020 Build Malaysia Bus Uncle Chatbot
Azure Weekend 2020 Build Malaysia Bus Uncle ChatbotAzure Weekend 2020 Build Malaysia Bus Uncle Chatbot
Azure Weekend 2020 Build Malaysia Bus Uncle Chatbot
 
Microsoft Azure的20大常见安全漏洞与配置错误
Microsoft Azure的20大常见安全漏洞与配置错误Microsoft Azure的20大常见安全漏洞与配置错误
Microsoft Azure的20大常见安全漏洞与配置错误
 
20 common security vulnerabilities and misconfiguration in Azure
20 common security vulnerabilities and misconfiguration in Azure20 common security vulnerabilities and misconfiguration in Azure
20 common security vulnerabilities and misconfiguration in Azure
 
Integrate Microsoft Graph with Azure Bot Services
Integrate Microsoft Graph with Azure Bot ServicesIntegrate Microsoft Graph with Azure Bot Services
Integrate Microsoft Graph with Azure Bot Services
 
Azure Sentinel with Office 365
Azure Sentinel with Office 365Azure Sentinel with Office 365
Azure Sentinel with Office 365
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 

Último (20)

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 

UWP with Microsoft Azure

  • 1. UWP WITH MICROSOFT AZURE BY ENG SOON CHEAH
  • 2. 1 UWP WITH MICROSOFT AZURE UWP with Microsoft Azure STORE IMAGE AND RETRIEVE IMAGE BY USING BLOB STORAGE Pre-Requirement 1. Install Visual Studio 2015 2. Install Azure SDK 3. Microsoft Azure Account Let Start to Code! Click the NEW > DATA SERVICES > STORAGE > QUICK CREATE > fill in the information > Create storage Account
  • 3. 2 UWP WITH MICROSOFT AZURE After the account is created you will find the dashboard. To access azure storage we have a storage account name and access keys. Click on manage access keys at the bottom and you will find them as below. We will now create a Windows UWP with the following UI. Add mobile services and azure storage nuget package foe the app. <Button x:Name="button" Content="Select Picture" HorizontalAlignment="Left" Margin="65,77,0,0" VerticalAlignment="Top" Height="68" Width="221" Click="SelectPic_clicked" FontSize="26.667"/> <Image x:Name="image" HorizontalAlignment="Left" Height="240" Margin="65,256,0,0" VerticalAlignment="Top" Width="335"/>
  • 4. 3 UWP WITH MICROSOFT AZURE In the button click event paste the following code, private async void SelectPic_clicked(object sender, RoutedEventArgs e) { try { FileOpenPicker fop = new FileOpenPicker(); fop.FileTypeFilter.Add(".jpg"); fop.FileTypeFilter.Add(".jpeg"); fop.FileTypeFilter.Add(".png"); fop.SuggestedStartLocation = PickerLocationId.PicturesLibrary; StorageFile sf = await fop.PickSingleFileAsync(); IRandomAccessStream str = await sf.OpenAsync(FileAccessMode.Read); CloudStorageAccount account; CloudBlobClient blobClient; CloudBlobContainer container; account = new CloudStorageAccount(new StorageCredentials("Insert your account name", "Insert your key"), true); blobClient = account.CreateCloudBlobClient(); container = blobClient.GetContainerReference("pictures"); await container.CreateIfNotExistsAsync(); BlobContainerPermissions per = new BlobContainerPermissions(); per.PublicAccess = BlobContainerPublicAccessType.Blob; await container.SetPermissionsAsync(per); CloudBlockBlob blob = container.GetBlockBlobReference(sf.Name); await blob.UploadFromFileAsync(sf); BitmapImage bmp = new BitmapImage(); bmp.UriSource = blob.Uri; BlobData imageData = new BlobData { imageUrl = blob.Uri.ToString(), name = sf.Name };
  • 5. 4 UWP WITH MICROSOFT AZURE await App.MobileService.GetTable<BlobData>().InsertAsync(imageData); var m1 = new MessageDialog("Image Uploaded").ShowAsync(); image.Source = bmp; } catch(Exception ex) { var m2 = new MessageDialog(ex.ToString()).ShowAsync(); } In the above code I have used FileOpenPicker to select an image. And used Mobile service to store blob name and url once uploaded. Use your account name and account key. I have used the following code for class. To retrieve images from the blob storage, I used mobile services to store the information. Use the following code to make the UI. Add the following is the c# code for retrieval of images. public class BlobData { public string id { get; set; } public string name { get; set; } public string imageUrl { get; set; } } <Button x:Name="button1" Content="Download Images" HorizontalAlignment="Left" Margin="618,64,0,0" VerticalAlignment="Top" Height="81" Width="259" FontSize="26.667" Click="Download_clicked"/> <ListView x:Name="ImageList" HorizontalAlignment="Left" Height="483" Margin="659,184,0,0" VerticalAlignment="Top" Width="496"> <ListView.ItemTemplate> <DataTemplate> <StackPanel> <TextBlock Text="{Binding name}" /> <Image Height="120" Width="150" Source="{Binding imageUrl}"/> </StackPanel> </DataTemplate> </ListView.ItemTemplate> </ListView> List<BlobData> allImages = await App.MobileService.GetTable<BlobData>().ToListAsync(); ImageList.ItemsSource = allImages;
  • 6. 5 UWP WITH MICROSOFT AZURE Screenshot 1 Screenshot 2 Screenshot 3
  • 7. 6 UWP WITH MICROSOFT AZURE Screenshot 4 Screenshot 5
  • 8. 7 UWP WITH MICROSOFT AZURE References: 1. How to operate Azure Blob and Table Storage in Windows Store apps https://code.msdn.microsoft.com/windowsapps/How-to-use-Windows-Azure-b3447051 2. Universal Windows Platform (UWP) App Development https://channel9.msdn.com/Series/Windows-10-development-for-absolute-beginners