public static async Task ChangeAccessPolicy(string connectionString, string containerName, string updatePermission)
        {
            CloudBlobClient    cloudBlobClient    = ConnectAzureStroage.ProcessConnection(connectionString);
            CloudBlobContainer cloudBlobContainer = cloudBlobClient.GetContainerReference(containerName);

            SetPermission.SetBlobPermission(cloudBlobContainer, updatePermission);
        }
예제 #2
0
        public static async Task DeleteBlobFileFromContainer(string connectionString, string containerName, string fileName)
        {
            CloudBlobClient    cloudBlobClient    = ConnectAzureStroage.ProcessConnection(connectionString);
            CloudBlobContainer cloudBlobContainer = cloudBlobClient.GetContainerReference(containerName);

            CloudBlockBlob blob = cloudBlobContainer.GetBlockBlobReference(fileName);

            blob.DeleteIfExists();
        }
        public static async Task DeleteBlobontainer(string connectionString, string containerName)
        {
            CloudBlobClient    cloudBlobClient    = ConnectAzureStroage.ProcessConnection(connectionString);
            CloudBlobContainer cloudBlobContainer = cloudBlobClient.GetContainerReference(containerName);

            if (cloudBlobContainer != null)
            {
                await cloudBlobContainer.DeleteIfExistsAsync();
            }
        }
예제 #4
0
        public static async Task DeleteContainerAndTempFiles(string connectionString, string containerName, string tempFilePath)
        {
            CloudBlobClient    cloudBlobClient    = ConnectAzureStroage.ProcessConnection(connectionString);
            CloudBlobContainer cloudBlobContainer = cloudBlobClient.GetContainerReference(containerName);

            if (cloudBlobContainer != null)
            {
                await cloudBlobContainer.DeleteIfExistsAsync();
            }
            File.Delete(tempFilePath);
        }
예제 #5
0
        public static async Task DownloadBlobFileStream(string connectionString, string containerName, string fileName)
        {
            CloudBlobClient    cloudBlobClient    = ConnectAzureStroage.ProcessConnection(connectionString);
            CloudBlobContainer cloudBlobContainer = cloudBlobClient.GetContainerReference(containerName);
            CloudBlockBlob     cloudBlockBlob     = cloudBlobContainer.GetBlockBlobReference(fileName);

            //Use this for stream data
            string home = GetDownloadFolderPath();
            Stream file = File.OpenWrite(home + @"\" + fileName);

            cloudBlockBlob.DownloadToStream(file);
        }
        public static async Task DownloadBlobFile(string connectionString, string containerName, string fileName)
        {
            CloudBlobClient    cloudBlobClient    = ConnectAzureStroage.ProcessConnection(connectionString);
            CloudBlobContainer cloudBlobContainer = cloudBlobClient.GetContainerReference(containerName);
            CloudBlockBlob     cloudBlockBlob     = cloudBlobContainer.GetBlockBlobReference(fileName);

            MemoryStream ms = new MemoryStream();
            await cloudBlockBlob.DownloadToStreamAsync(ms);

            Stream blobStream = cloudBlockBlob.OpenReadAsync().Result;

            //return null;//File(blobStream, cloudBlockBlob.Properties.ContentType, fileName);
        }
        public static async Task UploadBlobFile(string connectionString, string containerName, string mimeType, string localPath, string localFileName)
        {
            CloudBlobClient    cloudBlobClient    = ConnectAzureStroage.ProcessConnection(connectionString);
            CloudBlobContainer cloudBlobContainer = cloudBlobClient.GetContainerReference(containerName);

            string sourceFile = Path.Combine(localPath, localFileName);

            CloudBlockBlob cloudBlockBlob = cloudBlobContainer.GetBlockBlobReference("J<localFolderName>" + localFileName);
            await cloudBlockBlob.UploadFromFileAsync(sourceFile);

            //Set Content Type or Mime Type
            cloudBlockBlob.FetchAttributes();
            cloudBlockBlob.Properties.ContentType = mimeType;
            cloudBlockBlob.SetProperties();
        }
        public static async Task <bool> CreateBlobContainer(string connectionString, string containerName, string permission)
        {
            CloudBlobClient cloudBlobClient = ConnectAzureStroage.ProcessConnection(connectionString);

            if (cloudBlobClient != null)
            {
                CloudBlobContainer cloudBlobContainer =
                    cloudBlobClient.GetContainerReference(containerName);
                await cloudBlobContainer.CreateAsync();

                SetPermission.SetBlobPermission(cloudBlobContainer, permission);

                return(true);
            }
            return(false);
        }
예제 #9
0
        public static async Task UploadFileAsStream(string connectionString, string containerName, string mimeType, string localPath, string localFileName)
        {
            CloudBlobClient    cloudBlobClient    = ConnectAzureStroage.ProcessConnection(connectionString);
            CloudBlobContainer cloudBlobContainer = cloudBlobClient.GetContainerReference(containerName);
            // Create a file in your local any folder to upload to a blob.
            string sourceFile = Path.Combine(localPath, localFileName);

            CloudBlockBlob cloudBlockBlob = cloudBlobContainer.GetBlockBlobReference(localFileName);
            FileStream     fileStream     = File.OpenRead(localFileName);

            ///Read the stream at Code level
            //var streamReader = new StreamReader(fileStream);

            await cloudBlockBlob.UploadFromStreamAsync(fileStream);

            //Set Content Type or Mime Type
            cloudBlockBlob.FetchAttributes();
            cloudBlockBlob.Properties.ContentType = mimeType;
            cloudBlockBlob.SetProperties();
        }
        public static async Task <List <Uri> > GetBlobsInContainer(string connectionString, string containerName)
        {
            CloudBlobClient    cloudBlobClient    = ConnectAzureStroage.ProcessConnection(connectionString);
            CloudBlobContainer cloudBlobContainer = cloudBlobClient.GetContainerReference(containerName);
            // List the blobs in the container.
            BlobContinuationToken blobContinuationToken = null;
            List <Uri>            BlobList = new List <Uri>();

            do
            {
                var results = await cloudBlobContainer.ListBlobsSegmentedAsync(null, blobContinuationToken);

                // Get the value of the continuation token returned by the listing call.
                blobContinuationToken = results.ContinuationToken;
                foreach (IListBlobItem item in results.Results)
                {
                    BlobList.Add(item.Uri);
                }
            } while (blobContinuationToken != null); // Loop while the continuation token is not null.

            return(BlobList);
        }