Announcements
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Blob;
using Microsoft.WindowsAzure.Storage.File;
public void checkFolderName(str _filePath)
{
CloudBlobContainer blobcontainer;
CloudBlobClient blobClient;
var credential = new StorageCredentials("StorageAccountName", "StorageAccessKey");
var storageAccount = new CloudStorageAccount(credential, true);
blobClient = storageAccount.CreateCloudBlobClient();
blobcontainer = blobClient.GetContainerReference(_filePath);
}
//Example for https://community.dynamics.com/forums/thread/details/?threadid=3901f86c-6485-ef11-ac21-6045bda935ce
using Azure.Storage.Blobs;
using Azure.Storage.Blobs.Models;
internal final class CheckDirectory
{
//This example uses Azure.Storage.Blobs, as Microsoft.WindowsAzure.Storage will be deprecated in the near future
//You can find the documentation here: https://www.nuget.org/packages/Azure.Storage.blobs/
//Samples here: https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/storage/Azure.Storage.Blobs/samples
//NOTICE: I am using a connection string in this example, please adapt it to how you plan to authenticate
public static void Main(Args _args)
{
//Connection string
str connectionString = "https://*connectionString*";
//Blob prefix (As in your question, folder)
str prefix = "foo/bar/bas";
//Initializes a new blob container client: https://learn.microsoft.com/en-us/dotnet/api/azure.storage.blobs.blobcontainerclient?view=azure-dotnet
//Due to X++ limitations, .Net method parameters cannot be defaulted
if (new BlobContainerClient(new System.Uri(connectionString))
//Lists blobs in directory
.GetBlobs(
//Blob traits: https://learn.microsoft.com/en-us/dotnet/api/azure.storage.blobs.models.blobtraits?view=azure-dotnet
BlobTraits::None,
//Blob states: https://learn.microsoft.com/en-us/dotnet/api/azure.storage.blobs.models.blobstates?view=azure-dotnet
BlobStates::None,
//Blob prefix
prefix,
//Cancelation token (Note: Not used)
//https://learn.microsoft.com/en-us/dotnet/api/system.threading.cancellationtoken?view=net-8.0
new System.Threading.CancellationToken(false))
//Gets enumerator
.GetEnumerator()
//Iterate enumerator. Will return false at end of enumerator: https://learn.microsoft.com/en-us/dotnet/api/system.collections.ienumerator.movenext?view=net-8.0
.MoveNext())
{
info("Directory found!");
}
}
}
Using Azure.Storage.Blobs;
public void checkFolderName(str _filePath, str _containerName)
{
BlobContainerClient blobContainerClient;
//
blobContainerClient.GetBlobs(_filePath);
}
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Blob;
using Microsoft.WindowsAzure.Storage.File;
public void checkFolderName(str _filePath, str _containerName)
{
CloudBlobContainer blobcontainer;
CloudBlobClient blobClient;
var credential = new StorageCredentials("StorageAccountName", "StorageAccessKey");
var storageAccount = new CloudStorageAccount(credential, true);
blobClient = storageAccount.CreateCloudBlobClient();
blobcontainer = blobClient.GetContainerReference(_containerName);
CloudBlobDirectory cloudBlobDirectory = blobContainer.GetBlobDirectoryReference(_filePath);
}
var blobs = CloudBlobDirectory.ListBlobs(false, 0, null, null);
boolean directoryExists = blobs.Count() > 0;
var blobs = CloudBlobDirectory.ListBlobs();
boolean directoryExists = blobs.Count() > 0;
boolean directoryExists = CloudBlobDirectory.ListBlobs().Count() > 0
CloudBlobDirectory cloudBlobDirectory = blobContainer.GetBlobDirectoryReference('Folder1/Folder2');
if (!cloudBlobDirectory)
{
throw error ("Folder name not found");
}
André Arnaud de Cal... 291,359 Super User 2024 Season 2
Martin Dráb 230,370 Most Valuable Professional
nmaenpaa 101,156