This post shows X++ code used to list and read all files in Azure Blob container. Please refer to the following code.
/// <summary>
/// Start reading files from Blob
/// </summary>
public void startReadingFiles()
{
CloudBlobClient cloudBlobClient;
CloudBlobContainer cloudBlobInputContainer;
CloudStorageAccount cloudStorageAccount;
CloudBlockBlob iterationBlob, cloudBlockReadBlob;
Filename file, fileName;
System.Collections.IEnumerable list;
System.Collections.IEnumerator listEnumerator;
if (!payrollParameters.CUSBlobAccount || !payrollParameters.CUSBlobKey || !payrollParameters.CUSBlobgContainerInput)
{
throw error("Missing Parameters");
}
var storageCredentials = new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(payrollParameters.CUSBlobAccount, payrollParameters.CUSBlobKey);
try
{
cloudStorageAccount = new Microsoft.WindowsAzure.Storage.CloudStorageAccount(storageCredentials, true);
if (cloudStorageAccount)
{
cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();
cloudBlobInputContainer = cloudBlobClient.GetContainerReference(payrollParameters.CUSBlobgContainerInput);
list = new System.Collections.Generic.List<str>();
list = cloudBlobInputContainer.ListBlobs(null, false, 0, null, null);
listEnumerator = list.getEnumerator();
while (listEnumerator.moveNext())
{
iterationBlob = listEnumerator.get_Current();
if (iterationBlob.Exists(null, null))
{
file = iterationBlob.StorageUri.PrimaryUri.AbsoluteUri;
fileName = iterationBlob.Name;
cloudBlockReadBlob = cloudBlobInputContainer.GetBlockBlobReference(fileName);
System.IO.Strean readStream = cloudBlockReadBlob.OpenRead(null, null, null);
}
}
info("Read from Blob Successful");
}
}
catch
{
error("Unable to connect to the Blob");
}
}
/// Start reading files from Blob
/// </summary>
public void startReadingFiles()
{
CloudBlobClient cloudBlobClient;
CloudBlobContainer cloudBlobInputContainer;
CloudStorageAccount cloudStorageAccount;
CloudBlockBlob iterationBlob, cloudBlockReadBlob;
Filename file, fileName;
System.Collections.IEnumerable list;
System.Collections.IEnumerator listEnumerator;
if (!payrollParameters.CUSBlobAccount || !payrollParameters.CUSBlobKey || !payrollParameters.CUSBlobgContainerInput)
{
throw error("Missing Parameters");
}
var storageCredentials = new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(payrollParameters.CUSBlobAccount, payrollParameters.CUSBlobKey);
try
{
cloudStorageAccount = new Microsoft.WindowsAzure.Storage.CloudStorageAccount(storageCredentials, true);
if (cloudStorageAccount)
{
cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();
cloudBlobInputContainer = cloudBlobClient.GetContainerReference(payrollParameters.CUSBlobgContainerInput);
list = new System.Collections.Generic.List<str>();
list = cloudBlobInputContainer.ListBlobs(null, false, 0, null, null);
listEnumerator = list.getEnumerator();
while (listEnumerator.moveNext())
{
iterationBlob = listEnumerator.get_Current();
if (iterationBlob.Exists(null, null))
{
file = iterationBlob.StorageUri.PrimaryUri.AbsoluteUri;
fileName = iterationBlob.Name;
cloudBlockReadBlob = cloudBlobInputContainer.GetBlockBlobReference(fileName);
System.IO.Strean readStream = cloudBlockReadBlob.OpenRead(null, null, null);
}
}
info("Read from Blob Successful");
}
}
catch
{
error("Unable to connect to the Blob");
}
}
No comments:
Post a Comment