First Set the Connection String in Web Config File.
the Process Is
===============
<!--Azure Storage Account and BlobContainer Connection String (Satya)-->
<add key="StorageAccountName" value="satyastorageaccount" />
<add key="StorageAccountKey" value="fffq7R20Q0Pjomd73xSVt44re44dGXTANbM+Mx3iRFfegxjr1Fp6eqhzX2Uzvw==" />
<add key="blobcontainer" value="linkueblobcontainer" />
<!--End Azure ConnectionString-->
===============================================
Next In C# ASP .NET CODE
===============================
protected void Button1_Click(object sender, EventArgs e)
{
// this is Dynamically Sub Container name from frontend
string floder = txtcreatecontanier.Text;
// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = new CloudStorageAccount(new StorageCredentials("satyastorageaccount", "SrVl+wK6AxvPeFtT0JDxfs3xSVt44Q2BviaUvQfsdfs54434Fp6eqhzX2Uzvw=="), true);
// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve a reference to a container.
CloudBlobContainer container = blobClient.GetContainerReference(floder);
//// set the container to be public
//container.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob });
// Create the container if it doesn't already exist.
container.CreateIfNotExists();
// Retrieve reference to a blob named "myblob".
int count = 3;
for (int i = 0; i <= count; i++)
{
CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer cloudBlobContainer = cloudBlobClient.GetContainerReference(floder);
string obj = Server.MapPath("~/Images/accent.png");
var filename = Path.GetFileName(obj);
if (i == 0)
{
CloudBlobDirectory Img = container.GetDirectoryReference(floder + "image");
string imageName = Guid.NewGuid().ToString() + "-" + Path.GetExtension(filename);
CloudBlockBlob cloudBlockBlob = Img.GetBlockBlobReference(imageName);
CloudBlobClient blobClient1 = storageAccount.CreateCloudBlobClient();
ErpDataAccess.GetInstance.InsertData(Img.ToString());
using (var fs = File.OpenRead(obj))
{
cloudBlockBlob.UploadFromStream(fs);
}
}
if (i == 1)
{
CloudBlobDirectory Img = container.GetDirectoryReference(floder + "video");
string imageName = Guid.NewGuid().ToString() + "-" + Path.GetExtension(filename);
CloudBlockBlob cloudBlockBlob = Img.GetBlockBlobReference(imageName);
CloudBlobClient blobClient1 = storageAccount.CreateCloudBlobClient();
ErpDataAccess.GetInstance.InsertData(Img.ToString());
using (var fs = File.OpenRead(obj))
{
cloudBlockBlob.UploadFromStream(fs);
}
}
if (i == 2)
{
CloudBlobDirectory Img = container.GetDirectoryReference(floder + "files");
string imageName = Guid.NewGuid().ToString() + "-" + Path.GetExtension(filename);
CloudBlockBlob cloudBlockBlob = Img.GetBlockBlobReference(imageName);
CloudBlobClient blobClient1 = storageAccount.CreateCloudBlobClient();
ErpDataAccess.GetInstance.InsertData(Img.ToString());
using (var fs = File.OpenRead(obj))
{
cloudBlockBlob.UploadFromStream(fs);
}
}
if (i == 3)
{
CloudBlobDirectory Img = container.GetDirectoryReference(floder + "music");
string imageName = Guid.NewGuid().ToString() + "-" + Path.GetExtension(filename);
CloudBlockBlob cloudBlockBlob = Img.GetBlockBlobReference(imageName);
CloudBlobClient blobClient1 = storageAccount.CreateCloudBlobClient();
ErpDataAccess.GetInstance.InsertData(Img.ToString());
using (var fs = File.OpenRead(obj))
{
cloudBlockBlob.UploadFromStream(fs);
}
}
}
}
the Process Is
===============
<!--Azure Storage Account and BlobContainer Connection String (Satya)-->
<add key="StorageAccountName" value="satyastorageaccount" />
<add key="StorageAccountKey" value="fffq7R20Q0Pjomd73xSVt44re44dGXTANbM+Mx3iRFfegxjr1Fp6eqhzX2Uzvw==" />
<add key="blobcontainer" value="linkueblobcontainer" />
<!--End Azure ConnectionString-->
===============================================
Next In C# ASP .NET CODE
===============================
protected void Button1_Click(object sender, EventArgs e)
{
// this is Dynamically Sub Container name from frontend
string floder = txtcreatecontanier.Text;
// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = new CloudStorageAccount(new StorageCredentials("satyastorageaccount", "SrVl+wK6AxvPeFtT0JDxfs3xSVt44Q2BviaUvQfsdfs54434Fp6eqhzX2Uzvw=="), true);
// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve a reference to a container.
CloudBlobContainer container = blobClient.GetContainerReference(floder);
//// set the container to be public
//container.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob });
// Create the container if it doesn't already exist.
container.CreateIfNotExists();
// Retrieve reference to a blob named "myblob".
int count = 3;
for (int i = 0; i <= count; i++)
{
CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer cloudBlobContainer = cloudBlobClient.GetContainerReference(floder);
string obj = Server.MapPath("~/Images/accent.png");
var filename = Path.GetFileName(obj);
if (i == 0)
{
CloudBlobDirectory Img = container.GetDirectoryReference(floder + "image");
string imageName = Guid.NewGuid().ToString() + "-" + Path.GetExtension(filename);
CloudBlockBlob cloudBlockBlob = Img.GetBlockBlobReference(imageName);
CloudBlobClient blobClient1 = storageAccount.CreateCloudBlobClient();
ErpDataAccess.GetInstance.InsertData(Img.ToString());
using (var fs = File.OpenRead(obj))
{
cloudBlockBlob.UploadFromStream(fs);
}
}
if (i == 1)
{
CloudBlobDirectory Img = container.GetDirectoryReference(floder + "video");
string imageName = Guid.NewGuid().ToString() + "-" + Path.GetExtension(filename);
CloudBlockBlob cloudBlockBlob = Img.GetBlockBlobReference(imageName);
CloudBlobClient blobClient1 = storageAccount.CreateCloudBlobClient();
ErpDataAccess.GetInstance.InsertData(Img.ToString());
using (var fs = File.OpenRead(obj))
{
cloudBlockBlob.UploadFromStream(fs);
}
}
if (i == 2)
{
CloudBlobDirectory Img = container.GetDirectoryReference(floder + "files");
string imageName = Guid.NewGuid().ToString() + "-" + Path.GetExtension(filename);
CloudBlockBlob cloudBlockBlob = Img.GetBlockBlobReference(imageName);
CloudBlobClient blobClient1 = storageAccount.CreateCloudBlobClient();
ErpDataAccess.GetInstance.InsertData(Img.ToString());
using (var fs = File.OpenRead(obj))
{
cloudBlockBlob.UploadFromStream(fs);
}
}
if (i == 3)
{
CloudBlobDirectory Img = container.GetDirectoryReference(floder + "music");
string imageName = Guid.NewGuid().ToString() + "-" + Path.GetExtension(filename);
CloudBlockBlob cloudBlockBlob = Img.GetBlockBlobReference(imageName);
CloudBlobClient blobClient1 = storageAccount.CreateCloudBlobClient();
ErpDataAccess.GetInstance.InsertData(Img.ToString());
using (var fs = File.OpenRead(obj))
{
cloudBlockBlob.UploadFromStream(fs);
}
}
}
}
No comments:
Post a Comment