Created
January 31, 2019 09:45
-
-
Save donma/44337cadcacc440ab3f712d827e42c7c to your computer and use it in GitHub Desktop.
Azure Blob Storage Delete File
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var connsctionString = "your_connection_string"; | |
var cloudStorage = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(connsctionString); | |
var cloudBlobClient = cloudStorage.CreateCloudBlobClient(); | |
var cloudBlobContainer = cloudBlobClient.GetContainerReference("donmablogsample"); | |
var resultCreateContainer = cloudBlobContainer.CreateIfNotExistsAsync().Result; | |
Console.WriteLine("donmablogsample create already."); | |
//取得 TEST2/TEST21/ 目錄 | |
Microsoft.WindowsAzure.Storage.Blob.CloudBlobDirectory cloudBlobDirectory = | |
cloudBlobContainer.GetDirectoryReference("TEST2/TEST21/"); | |
Console.WriteLine("Delete File : TEST2/TEST21/sampleText8.json"); | |
// 如果存在就刪除,如果只是單純使用 DeleteAsync 如果不存在 會 Exception | |
// 如果檔案存在被刪除, result 才會為 true , 如果檔案不存在 則 result 為 false | |
var result = cloudBlobDirectory.GetBlockBlobReference("sampleText8.json").DeleteIfExistsAsync().GetAwaiter().GetResult(); | |
Console.WriteLine(result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment