Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Azure by (13.1k points)
Can anyone help me how exactly I can able to upload a c# file?

1 Answer

0 votes
by (26.7k points)

To upload a c# file, given is the following code you can try.

using Microsoft.WindowsAzure.Storage;

using Microsoft.WindowsAzure.Storage.Auth;

using Microsoft.WindowsAzure.Storage.Blob;    

// Retrieve storage account from connection string.

    CloudStorageAccount storageAccount = CloudStorageAccount.Parse("StorageKey");

// Create the blob client.

CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

// Retrieve reference to a previously created container.

CloudBlobContainer container = blobClient.GetContainerReference("mycontainer");

// Retrieve reference to a blob named "myblob".

CloudBlockBlob blockBlob = container.GetBlockBlobReference("myblob");

// Create or overwrite the "myblob" blob with contents from a local file.

using (var fileStream = System.IO.File.OpenRead(@"path\myfile"))

{

    await blockBlob.UploadFromStreamAsync(fileStream);

}

I hope this will work.

Want to become an Azure Expert? join Azure Training now!!

Browse Categories

...