I have in my container 3000 files.In my gridview I am show the list of container blobs but 3000 is too much and is not good for performance (my thought :) ).
I need a paging code , example my grid pagesize is 50 I will show the first 50 blob in my container for my first page in gridview.Of course I need in pageindexchanging more code :)
Or does it not affect performance ?
According to your description, I suggest you could try to use azure storage SDK's ListBlobsSegmented method to achieve your requirement.
The ListBlobsSegmented inclue maxResults parameter.
maxResults: A non-negative integer value that indicates the maximum number of results to be returned at a time, up to the per-operation limit of 5000. If this value is null, the maximum possible number of results will be returned, up to 5000.
So you could just search 50 records when your page is load firstly.
When your page index changed, you could call the search method to search the right number of blobs according to gridview index.
Notice:To include the performance, we will not get all the blobs at once to know how many blobs in your container. So we couldn't know the total number of blobs.I suggest you could search 100 blobs at first time, if the customer click the page 2, it will search next 100 blobs.
Here is a example demo, hope it gives you some tips: Gridview:
<asp:GridView ID="GridView1" AllowPaging="true" PageSize="50" OnPageIndexChanging="GridView1_PageIndexChanging" runat="server">
</asp:GridView>
Code behind:
BlobContinuationToken continuationToken = null;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//1*100 is the numebr of blobs you will list
ListBlobResult(1*100);
}
}
public void ListBlobResult(int index)
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse("connectionstring");
var client = storageAccount.CreateCloudBlobClient();
var container = client.GetContainerReference("foo2");
string prefix = null;
bool useFlatBlobListing = true;
BlobListingDetails blobListingDetails = BlobListingDetails.All;
// int maxBlobsPerRequest = 50;
List<IListBlobItem> blobs = new List<IListBlobItem>();
if (index <= 5000)
{
var listingResult = container.ListBlobsSegmented(prefix, useFlatBlobListing, blobListingDetails, index, continuationToken, null, null);
continuationToken = listingResult.ContinuationToken;
blobs.AddRange(listingResult.Results);
}
else
{
do
{
var listingResult = container.ListBlobsSegmented(prefix, useFlatBlobListing, blobListingDetails, index, continuationToken, null, null);
continuationToken = listingResult.ContinuationToken;
blobs.AddRange(listingResult.Results);
index = index - 5000;
}
while (continuationToken != null);
}
DataTable d1 = new DataTable();
d1.Columns.Add("Id");
d1.Columns.Add("Url");
foreach (var item in blobs)
{
if (item.GetType() == typeof(CloudBlockBlob))
{
CloudBlockBlob blob = (CloudBlockBlob)item;
d1.Rows.Add(blob.Name, blob.Uri);
}
}
GridView1.DataSource = d1;
GridView1.DataBind();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
//(e.NewPageIndex*100)+100 is the numebr of blobs you will list
ListBlobResult((e.NewPageIndex*100)+100);
}