我有一些代码可以将容器的blob和文件夹列出到asp.net listBox中。双击属于文件夹的listItem,该文件夹的内容将转到listBox。问题是,这在第一层之后的任何文件夹上都不起作用,listBox变成空的。
我的论点是,我的代码将引用的目录放在容器中,由于子文件夹不直接位于容器中,因此无法识别它,并且listBox为空。
protected void Page_Load(object sender, EventArgs e)
{
if (Request["__EVENTARGUMENT"] != null && Request["__EVENTARGUMENT"] == "expand")
{
List<string> ListBlobsInFolder()
{
List<string> blobs = new List<string>();
CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse("MYCONNECTIONSTRING");
CloudBlobClient cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();
CloudBlobContainer container = cloudBlobClient.GetContainerReference("testcontainer");
ListItem listItem = lboxLogs.SelectedItem;
CloudBlobDirectory directory = container.GetDirectoryReference(listItem.ToString());
IEnumerable<IListBlobItem> blobList = directory.ListBlobs();
foreach (IListBlobItem item in blobList)
{
blobs.Add(string.Format("{0}", item.Uri.Segments.Last()));
}
return blobs;
//IEnumerable<IListBlobItem> subDirectoryList = subDirectory.ListBlobs();
}
try
{
if (lboxLogs.SelectedItem.ToString().EndsWith("/"))
{
try
{
lboxLogs.DataSource = ListBlobsInFolder();
lboxLogs.DataBind();
}
catch (System.NullReferenceException)
{
//do nothing
}
}
}
catch (NullReferenceException)
{
//do nothing
}
}
lboxLogs.Attributes.Add("ondblclick", ClientScript.GetPostBackEventReference(lboxLogs, "expand"));
}
我不确定如何处理这个问题,这样当我双击时,目录引用将在必要时从容器中,在必要时在另一个文件夹中。
发布于 2019-07-16 03:11:25
当涉及到Azure blob的文件夹结构时,它当前是一个虚拟文件夹,访问这些虚拟文件夹中的任何内容的方式,它需要将虚拟目录的名称附加到其中的blob,例如:
['Virtual-Folder/2019-02-06 10_43_04-Access Control - Microsoft Azure.png', 'Virtual-Folder/Boards.png', 'storage2.gif']
当列出容器中包含一个名为" virtual - folder“的虚拟文件夹的blob列表时,可以通过以下名称访问其中的blob:"'Virtual-Folder/Boards.png'”如果我尝试仅调用"Boards.png“,它将不起作用。
我还使用python SDK在github中编写了一些示例,请随时查看代码示例here。
https://stackoverflow.com/questions/57044883
复制相似问题