2010-04-11 31 views
1

我想在我的blob中創建一些子目錄。但它不工作了好Windows Azure:在blob中創建一個子目錄

這裏是我的代碼

protected void ButUpload_click(object sender, EventArgs e) 
    { 
     // store upladed file as a blob storage 
     if (uplFileUpload.HasFile) 
     { 
      name = uplFileUpload.FileName; 
      // get refernce to the cloud blob container 
      CloudBlobContainer blobContainer = cloudBlobClient.GetContainerReference("documents"); 

      if (textbox.Text != "") 
      { 
       name = textbox.Text + "/" + name; 
      } 
      // set the name for the uploading files 
      string UploadDocName = name; 

      // get the blob reference and set the metadata properties 
      CloudBlockBlob blob = blobContainer.GetBlockBlobReference(UploadDocName); 
      blob.Metadata["FILETYPE"] = "text"; 
      blob.Properties.ContentType = uplFileUpload.PostedFile.ContentType; 

      // upload the blob to the storage 
      blob.UploadFromStream(uplFileUpload.FileContent); 

     } 
    } 

我所做的是,如果我要創建一個子目錄,我會在文字框中輸入子目錄的名稱。

例如,如果我需要創建一個名爲文件「的test.txt」的分目錄內「文件」 然後,我textbox.text =文件uplFileUpload.FileName =測試。 TXT

現在我將它們連接起來,並上傳到BLOB .. 但它不工作以及.. 我想起來了 https://test.core.windows.net/documents/files/

我沒有得到整個事情 我期待https://test.core.windows.net/documents/files/test.txt

我在做什麼錯... 如何創建BLOB中的子目錄。

回答

2

您可以使用blobContainer.ListBlobs(新BlobRequestOptions {UseFlatBlobListing =真});以獲得您正在查找的視圖(忽略斜槓並僅列出所有斑點)。

0

乍一看,這段代碼看起來很好。在調用GetBlockBlobReference()之前,我會遍歷代碼並驗證UploadDocName是您期望的。

0

GetBlockBlobReference()後檢查blob.Uri嗎?

順便說一句,每次我做這種類型的代碼,我使用GetBlobReference()來代替......我想知道是否有一些機會在那裏有所不同? (這將是非常奇怪的。)

0

它現在的工作......這是我的錯誤顯示斑點

protected void DisplayBlob_click(object sender, EventArgs e) 
    { 
     // get container referrence 
     CloudBlobContainer blobContainer = cloudBlobClient.GetContainerReference("documents"); 

     // create list 
     IEnumerable<IListBlobItem> blobList = blobContainer.ListBlobs(); 

     // display name on the page 
     string names = string.Empty; 

     foreach (IListBlobItem item in blobList) 
     { 
      names += item.Uri + "<br />"; 

     } 

     LURI.Text = names; 
    } 

的內容只顯示當前目錄下,並且不穿越到子目錄....

感謝....

相關問題