I'm putting together a small project management site where a user can upload relevant documents to a project using Azure Blob storage.
I can upload, view the list of blobs and download the blobs, but what I want to do is show the blobs in a list without all the container & path information.
Here's the C#
public ActionResult doclist(int projectid)
{
CloudConfigurationManager.GetSetting("StorageConnectionString", true);
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
CloudConfigurationManager.GetSetting("StorageConnectionString"));
// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve reference to a previously created container.
CloudBlobContainer container = blobClient.GetContainerReference(containername);
List<CloudBlockBlob> blobs = new List<CloudBlockBlob>();
//foreach (IListBlobItem item in container.ListBlobs(null, true))
foreach (IListBlobItem item in container.ListBlobs((containername + "/" + projectid.ToString() + "/").ToString()))
{
CloudBlockBlob blob = (CloudBlockBlob)item;
blobs.Add(blob);
}
return View(blobs);
}
The view is essentially just a simple
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelitem => item.Name)
</td>
<td>
@Html.DisplayFor(modelitem => item.Properties.Length)
</td>
<td>
@string.Format("{0:dd-MM-yyyy}", item.Properties.LastModified)
</td>
<td>
@Html.ActionLink("Download", "Download", "Projects", new { filename = item.Name}, new { @class = "btn btn-primary" })
</td>
</tr>
}
I end up with a item.Name value like "container/project1/document1.jpg" "container/project1/document2.pdf" etc
All I want to display is "document1.jog" "document2.pdf"
I've tried a simple replace in the HTML, which I've not managed to get it to work.
I've also tried fiddling with the blob data in the C# to change the URI, but don't want that to affect how I download the blob.
Guessing I've missed something really simple here, but this is the first time I've used Blob storage etc.
Am I better off writing this sort of data to a database table and retrieving it from there?