question

PaulBill-8748 avatar image
0 Votes"
PaulBill-8748 asked PaulBill-8748 edited

What would be the equivalent code in Azure.Storage - v12.x be for the old Imports Microsoft.Azure Imports Microsoft.WindowsAzure.Storage Imports Microsoft.WindowsAzure.Storage.Blob?

I have a Visual Basic desktop application that stored, retrieved and copied files and images to my Azure Storage Account Container and created blobs. I'm trying to switch to the new Azure Storage but am having trouble finding the equivalents to the code listed below. Does anyone know what the code below would be for the new Azure.Storage - v12.x?


Imports Azure
Imports Microsoft.WindowsAzure.Storage
Imports Microsoft.WindowsAzure.Storage.Blob

Dim storageacc As CloudStorageAccount = CloudStorageAccount.Parse(storageconn)
Dim blobClient As CloudBlobClient = storageacc.CreateCloudBlobClient()

Dim container As CloudBlobContainer = blobClient.GetContainerReference(strAgency & strAzureDirPath)


Dim blobCopy As CloudBlockBlob = container.GetBlockBlobReference(NewFileName)
Dim blockBlob As CloudBlockBlob = container.GetBlockBlobReference(uGridFiles.Selected.Rows(intJ).Cells("FileName").Text)
Dim source = container.GetBlockBlobReference(blockBlob.Name)
Dim target = container.GetBlockBlobReference(blobCopy.Name)

blobCopy.StartCopy(blockBlob)

While blobCopy.CopyState.Status = CopyStatus.Pending
System.Threading.Tasks.Task.Delay(100).Wait()
End While

If blobCopy.CopyState.Status <> CopyStatus.Success Then Throw New ApplicationException("Rename failed: " & blobCopy.CopyState.Status)

blockBlob.DeleteIfExists()



Any help is appreciated.

dotnet-visual-basicazure-storage-accountsazure-blob-storage
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

SumanthMarigowda-MSFT avatar image
0 Votes"
SumanthMarigowda-MSFT answered PaulBill-8748 edited

@PaulBill-8748 Firstly, Apologies for the delay response! As I understand you want to move from Visual Basic to .Net am I correct?

This article demonstrates how to copy a blob in an Azure Storage account. It also shows how to abort an asynchronous copy operation. The example code uses the Azure Storage client libraries. https://docs.microsoft.com/en-us/azure/storage/blobs/storage-blob-copy?tabs=dotnet

Please let us know if you have any further queries. I’m happy to assist you further.


Please do not forget to 186431-screenshot-2021-12-10-121802.png and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.





· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Not exactly, but I did finally figure out my necessary changes. The replacement code is below and working in Visual Basic on a desktop application storing files and images in Azure Storage:

Imports Azure
Imports Azure.Storage.Blobs
Imports Azure.Storage.Blobs.Models

Dim storageacct As BlobServiceClient = New BlobServiceClient(storageconn)


Dim container As BlobContainerClient = storageacct.GetBlobContainerClient(strContainer)

Dim isExist As Boolean = container.Exists()

If Not isExist Then
container.Create()
End If

Dim blobClient As BlobClient = container.GetBlobClient(txtNumber.Text & "/" & uGridFiles.Selected.Rows(intJ).Cells("FileName").Text)

Dim blobCopy As BlobClient = container.GetBlobClient(txtNumber.Text & "/" & NewFileName)
Dim blockBlob As BlobClient = container.GetBlobClient(txtNumber.Text & "/" & uGridFiles.Selected.Rows(intJ).Cells("FileName").Text)
Dim source = container.GetBlobClient(blockBlob.Name)
Dim target = container.GetBlobClient(blobCopy.Name)


blobCopy.StartCopyFromUri(blockBlob.Uri)
While blobCopy.StartCopyFromUri(blockBlob.Uri).UpdateStatus.Status = CopyStatus.Pending
System.Threading.Tasks.Task.Delay(100).Wait()
End While
Dim blobcopyprop As BlobProperties = blobCopy.GetProperties()
If blobcopyprop.BlobCopyStatus <> CopyStatus.Success Then Throw New ApplicationException("Rename failed: " & blobCopy.StartCopyFromUri(blockBlob.Uri).UpdateStatus.Status)


blockBlob.DeleteIfExists()


Thanks for the repsonse!

0 Votes 0 ·