Hello Chandrakant Pawle,
Thank you for posting your query here!
First, you need to make sure that you have the Azure.Storage.Blobs
NuGet package installed:
You can install it via NuGet Package Manager in Visual Studio.
Install-Package Azure.Storage.Blobs
Can you please try with the following updated code and let us know if it helps:
using Azure.Storage.Blobs;
using System;
using System.IO;
using System.Web.UI;
using System.Web.UI.WebControls;
protected void UploadButton_Click(object sender, EventArgs e)
{
try
{
// Retrieve the connection string from configuration (e.g., Web.config)
string storageConnectionString = System.Configuration.ConfigurationManager.AppSettings["StorageConnectionString"];
// Name of your container
string containerName = "your-container-name";
// Create a BlobServiceClient
BlobServiceClient blobServiceClient = new BlobServiceClient(storageConnectionString);
// Get the container client object
BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(containerName);
// Create the container if it does not exist
containerClient.CreateIfNotExists();
// Get a reference to a blob
BlobClient blobClient = containerClient.GetBlobClient(Path.GetFileName(FileUploadControl.FileName));
if (FileUploadControl.HasFile && FileUploadControl.PostedFile.ContentLength > 0)
{
// Upload the file content
using (Stream uploadFileStream = FileUploadControl.PostedFile.InputStream)
{
blobClient.Upload(uploadFileStream, overwrite: true);
}
// Provide feedback to the user
UploadStatusLabel.Text = "File uploaded successfully!";
}
else
{
// Inform user that a file was not selected or file is empty
UploadStatusLabel.Text = "Please select a file to upload.";
}
}
catch (Exception ex)
{
// Handle any errors that occurred during upload
UploadStatusLabel.Text = "Upload failed. Error: " + ex.Message;
}
}
Do let us know if you have any further queries. I’m happy to assist you further.
Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.