Skip to content

Instantly share code, notes, and snippets.

@ajpinedam
Created January 17, 2017 02:18
Show Gist options
  • Save ajpinedam/f8ed9eadc3c79dd10c21084928352074 to your computer and use it in GitHub Desktop.
Save ajpinedam/f8ed9eadc3c79dd10c21084928352074 to your computer and use it in GitHub Desktop.
async Task GetResourceFile (string fileStorageName, string directory, string fileName)
{
var storageInstance = CloudStorageAccount.Parse (Settings.AzureKey);
var fileClient = storageInstance.CreateCloudFileClient ();
var share = fileClient.GetShareReference (fileStorageName);
if (!await share.ExistsAsync ())
{
return;
}
var root = share.GetRootDirectoryReference ();
//Igual si el archivo esta directamente en el root no es necesario esto
// y puedes pasar al metodo de mas abajo que busca el archivo directamente.
var myFilesDirectory = root.GetDirectoryReference (directory);
if (!await myFilesDirectory.ExistsAsync ())
{
return;
}
var file = myFilesDirectory.GetFileReference (fileName);
if (!await file.ExistsAsync ())
{
return;
}
//aqui estoy haciendo esto para mostrar el contenido pero si deseas descargalo debes usar el otro metodo
// await file.DownloadToFileAsync ("ruta_archivo_con_extension", System.IO.FileMode.Create);
var text = await file.DownloadTextAsync ();
_fileEditText.Text = text;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment