【发布时间】:2019-07-16 03:11:25
【问题描述】:
我有将容器的 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"));
}
我不确定如何解决这个问题,这样当我双击时,目录引用将在必要时来自容器内,并在必要时来自另一个文件夹。
【问题讨论】:
标签: c# listbox azure-blob-storage