Example #1
0
        public List <string> ClearAllBlobs()
        {
            // Get a reference to out container.
            var container = GetContainer();

            var result = new List <string>();

            // Loop over items within the container and output the length and URI.
            foreach (IListBlobItem item in container.ListBlobs(null, false))
            {
                if (item.GetType() == typeof(CloudBlockBlob))
                {
                    CloudBlockBlob blob = (CloudBlockBlob)item;
                    blob.Delete();

                    result.Add(string.Format("Deleted block blob of length {0}: {1}", blob.Properties.Length, blob.Uri));
                }
                else if (item.GetType() == typeof(CloudPageBlob))
                {
                    CloudPageBlob pageBlob = (CloudPageBlob)item;
                    pageBlob.Delete();

                    result.Add(string.Format("Deleted page blob of length {0}: {1}", pageBlob.Properties.Length, pageBlob.Uri));
                }
                else if (item.GetType() == typeof(CloudBlobDirectory))
                {
                    CloudBlobDirectory directory = (CloudBlobDirectory)item;
                    var d = container.GetDirectoryReference(directory.Uri.ToString());

                    result.Add(string.Format("Deleted directory: {0}", directory.Uri));
                }
            }

            return(result);
        }
Example #2
0
        //Удаление всех дисков
        public static void DeleteAllStorageVHD()
        {
            try
            {
                CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
                // Create the blob client.
                CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
                // Retrieve reference to a previously created container.
                CloudBlobContainer container = blobClient.GetContainerReference("vmcontainerd7962b02-629a-468a-a901-266a6e53cf77");
                // Loop over items within the container and output the length and URI.

                foreach (IListBlobItem item in container.ListBlobs(null, false))
                {
                    CloudPageBlob pageBlob = item as CloudPageBlob;
                    if (pageBlob != null)
                    {
                        try
                        {
                            pageBlob.Delete();
                        }
                        catch { }
                    }
                }
            }
            catch (Exception exp)
            {
                Trace.TraceInformation("Failed deleting storage VHD's");
                TraceHelper.TraceException(exp);
            }
            Thread.Sleep(60000);
        }