Windows Azure:在blob中创build一个子目录

我想在我的blob中创build一些子目录。 但是运作不好

这是我的代码

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); } } 

我所做的是,如果我必须创build一个子目录,我将在文本框中input子目录的名称。

例如,如果我需要在子目录“files”中创build一个名为“test.txt”文件,那么我的 textbox.text = filesuplFileUpload.FileName = test.txt

现在我将它们连接起来,并上传到blob ..但它是行不通的..我只是得到https://test.core.windows.net/documents/files/

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

我在做什么错了…如何在blob内创build子目录。

你可以使用blobContainer.ListBlobs(新的BlobRequestOptions {UseFlatBlobListing = true}); 获得你正在寻找的视图(忽略斜杠,只是列出了所有的斑点)。

乍一看,这段代码看起来很好。 我会遍历代码,并验证在调用GetBlockBlobReference()之前UploadDocName是您所期望的。

在做GetBlockBlobReference()之后检查blob.Uri?

顺便说一句,每次我做这样的代码,我使用GetBlobReference()而不是…我想知道是否有一些机会有差异吗? (这将是非常奇怪的。)

它的工作现在…这是我的错误在显示blob的内容

 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; } 

它只显示当前目录,不会遍历子目录….

谢谢….