当前位置: 首页>>代码示例>>C#>>正文


C# CloudBlobContainer.ListBlobs方法代码示例

本文整理汇总了C#中Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer.ListBlobs方法的典型用法代码示例。如果您正苦于以下问题:C# CloudBlobContainer.ListBlobs方法的具体用法?C# CloudBlobContainer.ListBlobs怎么用?C# CloudBlobContainer.ListBlobs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer的用法示例。


在下文中一共展示了CloudBlobContainer.ListBlobs方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UpdateFireblob

        public async Task UpdateFireblob(CloudBlobContainer blobContainer)
        {

            try
            {
                IFirebaseConfig config = new FirebaseConfig
                {
                    AuthSecret = "Gg5t1fSLC0WWPVM1VMoNxlM29qO1s53dEso7Jrfp",
                    BasePath = "https://ringtoneapp.firebaseio.com/"
                };

                IFirebaseClient client = new FirebaseClient(config);
                var list = blobContainer.ListBlobs();
                List<CloudBlockBlob> blobNames = list.OfType<CloudBlockBlob>().ToList();

                // SET
                var todo = new Todo();

                List<Todo> todoList = new List<Todo>();
                List<UploadDataModel> MetaList = new List<UploadDataModel>();
                foreach (var blb in blobNames)
                {
                    blb.FetchAttributes();
                    Todo td = new Todo();
                    td.name = blb.Name;
                    td.url = blb.Uri.AbsoluteUri.ToString();
                    if (blb.Metadata.Values.Count > 0)
                    {
                        td.Category = blb.Metadata.Values.ElementAt(0);
                        td.UserName = blb.Metadata.Values.ElementAt(1);
                        td.Number = blb.Metadata.Values.ElementAt(2);
                        td.Email = blb.Metadata.Values.ElementAt(3);
                        td.Comments = blb.Metadata.Values.ElementAt(4);
                    }
                    todoList.Add(td);
                }

                SetResponse response = await client.SetAsync(FirebaseContainer, todoList);
                List<Todo> setresult = response.ResultAs<List<Todo>>();
            }
            catch (Exception e)
            {

            }

            //GET
            //FirebaseResponse getresponse = await client.GetAsync("ringtones");
            //List<Todo> gettodo = response.ResultAs<List<Todo>>(); //The response will contain the data being retreived
        }
开发者ID:rohngonnarock,项目名称:BlobStorage,代码行数:49,代码来源:Todo.cs

示例2: ListBlobs

        public static void ListBlobs(CloudBlobContainer blobContainer, BlobListing blobListing, String prefix = null)
        {
            if (blobListing == BlobListing.Flat)
              {
            foreach (var blockBlob in blobContainer.ListBlobs(prefix: null, useFlatBlobListing: true))
            {
              Console.WriteLine("{0,-10} - {1}", @"Blob", ((CloudBlockBlob)blockBlob).Name);
              Console.WriteLine("{0,-10} - {1}", String.Empty, blockBlob.Uri);
            }
              }
              else if (blobListing == BlobListing.Hierarchical)
              {
            foreach (var blockBlob in blobContainer.ListBlobs(prefix: prefix, useFlatBlobListing: false))
            {
              if (blockBlob is CloudBlockBlob)
              {
            Console.WriteLine("{0,-10} - {1}", @"Blob", ((CloudBlockBlob)blockBlob).Name);
            Console.WriteLine("{0,-10} - {1}", String.Empty, blockBlob.Uri);
              }
              else if (blockBlob is CloudBlobDirectory)
              {
            Console.WriteLine("{0,-10} - {1}", @"Directory", ((CloudBlobDirectory)blockBlob).Prefix);
            Console.WriteLine("{0,-10} - {1}", String.Empty, blockBlob.Uri);

            ListBlobs(blobContainer, BlobListing.Hierarchical, ((CloudBlobDirectory)blockBlob).Prefix);
              }
            }
              }
        }
开发者ID:paulbouwer,项目名称:BlobStorageDemos,代码行数:29,代码来源:03_ListBlobs.cs

示例3: BlobFileProvider

        public BlobFileProvider(IEnumerable<string> locations)
            : base()
        {
            _storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);
            _blobClient = _storageAccount.CreateCloudBlobClient();
            _container = _blobClient.GetContainerReference("data");
            _container.CreateIfNotExists();

            _strings = new List<string>();
            foreach(string location in locations) {
                foreach (IListBlobItem item in _container.ListBlobs(location,true))
                {
                    if (item.GetType() == typeof(CloudBlockBlob))
                    {
                        CloudBlockBlob blob = (CloudBlockBlob)item;
                        string text;
                        using (var memoryStream = new MemoryStream())
                        {
                            blob.DownloadToStream(memoryStream);
                            text = Encoding.UTF8.GetString(memoryStream.ToArray());
                            if (text[0] == _byteOrderMarkUtf8[0])
                            {
                               text= text.Remove(0,_byteOrderMarkUtf8.Length);
                            }
                            _strings.Add(text);
                        }
                    }
                }
            }
        }
开发者ID:crb02005,项目名称:RandomTables,代码行数:30,代码来源:BlobProvider.cs

示例4: GetBlobs

 public List<CloudBlockBlob> GetBlobs(CloudBlobContainer container, string filter = "")
 {
     return container.ListBlobs()
             .OfType<CloudBlockBlob>()
             .Where(b => String.IsNullOrEmpty(filter) || b.Name.Contains(filter))
             .ToList();
 }
开发者ID:sxkote,项目名称:sxcore,代码行数:7,代码来源:AzureFileStorageService.cs

示例5: AzureBlobStorageUploader

 /// <summary>
 /// Initializes a new instance of the <see cref="AzureBlobStorageUploader"/> class
 /// </summary>
 /// <param name="files">The file collection to upload</param>
 /// <param name="container">The Azure Blob Container to upload to</param>
 public AzureBlobStorageUploader(UploadableFileCollection files, CloudBlobContainer container)
     : base(files)
 {
     _container = container;
     var existingFileNames = new List<string>(container.ListBlobs(null, false)
         .Select(n => WebUtility.UrlDecode(n.Uri.Segments.Last()))).ToArray();
     files.AssertAndResolveUniqueSaveNames(existingFileNames);
 }
开发者ID:rikproDVC,项目名称:RikPronk.FileUpload,代码行数:13,代码来源:AzureBlobStorageUploader.cs

示例6: ClearContainer

 public static void ClearContainer(CloudBlobContainer container, string prefix)
 {
     foreach (CloudBlockBlob blob in container.ListBlobs(useFlatBlobListing: true).Where(b => b is CloudBlockBlob).Select(b => b as CloudBlockBlob))
     {
         if (blob.Name.StartsWith(prefix))
         {
             Console.WriteLine("Deleting blob '" + blob.Uri.ToString() + "'");
             blob.Delete();
         }
     }
 }
开发者ID:abbottdev,项目名称:PowerArgs,代码行数:11,代码来源:Helpers.cs

示例7: TestAccess

        private static void TestAccess(BlobContainerPublicAccessType accessType, CloudBlobContainer container, CloudBlob inputBlob)
        {
            StorageCredentials credentials = new StorageCredentials();
            container = new CloudBlobContainer(container.Uri, credentials);
            CloudPageBlob blob = new CloudPageBlob(inputBlob.Uri, credentials);

            if (accessType.Equals(BlobContainerPublicAccessType.Container))
            {
                blob.FetchAttributes();
                container.ListBlobs().ToArray();
                container.FetchAttributes();
            }
            else if (accessType.Equals(BlobContainerPublicAccessType.Blob))
            {
                blob.FetchAttributes();
                TestHelper.ExpectedException(
                    () => container.ListBlobs().ToArray(),
                    "List blobs while public access does not allow for listing",
                    HttpStatusCode.NotFound);
                TestHelper.ExpectedException(
                    () => container.FetchAttributes(),
                    "Fetch container attributes while public access does not allow",
                    HttpStatusCode.NotFound);
            }
            else
            {
                TestHelper.ExpectedException(
                    () => blob.FetchAttributes(),
                    "Fetch blob attributes while public access does not allow",
                    HttpStatusCode.NotFound);
                TestHelper.ExpectedException(
                    () => container.ListBlobs().ToArray(),
                    "List blobs while public access does not allow for listing",
                    HttpStatusCode.NotFound);
                TestHelper.ExpectedException(
                    () => container.FetchAttributes(),
                    "Fetch container attributes while public access does not allow",
                    HttpStatusCode.NotFound);
            }
        }
开发者ID:Gajendra-Bahakar,项目名称:azure-storage-net,代码行数:40,代码来源:CloudBlobContainerTest.cs

示例8: CreateAssetFromExistingBlobs

        /// <summary>
        /// Creates a new asset and copies blobs from the specifed storage account.
        /// </summary>
        /// <param name="mediaBlobContainer">The specified blob container.</param>
        /// <returns>The new asset.</returns>
        public static IAsset CreateAssetFromExistingBlobs(CloudBlobContainer mediaBlobContainer)
        {
            // Create a new asset.
            IAsset asset = _context.Assets.Create("NewAsset_" + Guid.NewGuid(), AssetCreationOptions.None);

            IAccessPolicy writePolicy = _context.AccessPolicies.Create("writePolicy",
                TimeSpan.FromHours(24), AccessPermissions.Write);
            ILocator destinationLocator = _context.Locators.CreateLocator(LocatorType.Sas, asset, writePolicy);

            CloudBlobClient destBlobStorage = _destinationStorageAccount.CreateCloudBlobClient();

            // Get the asset container URI and Blob copy from mediaContainer to assetContainer.
            string destinationContainerName = (new Uri(destinationLocator.Path)).Segments[1];

            CloudBlobContainer assetContainer =
                destBlobStorage.GetContainerReference(destinationContainerName);

            if (assetContainer.CreateIfNotExists())
            {
                assetContainer.SetPermissions(new BlobContainerPermissions
                {
                    PublicAccess = BlobContainerPublicAccessType.Blob
                });
            }

            var blobList = mediaBlobContainer.ListBlobs();
            foreach (var sourceBlob in blobList)
            {
                var assetFile = asset.AssetFiles.Create((sourceBlob as ICloudBlob).Name);
                CopyBlob(sourceBlob as ICloudBlob, assetContainer);
                assetFile.ContentFileSize = (sourceBlob as ICloudBlob).Properties.Length;
                assetFile.Update();
            }

            asset.Update();

            destinationLocator.Delete();
            writePolicy.Delete();

            // Since we copied a set of Smooth Streaming files,
            // set the .ism file to be the primary file.
            // If we, for example, copied an .mp4, then the mp4 would be the primary file.
            SetISMFileAsPrimary(asset);

            return asset;
        }
开发者ID:Azure-Samples,项目名称:media-services-dotnet-copy-blob-into-asset,代码行数:51,代码来源:Program.cs

示例9: ListAllBlobs

 public static void ListAllBlobs(CloudBlobContainer container)
 {
     foreach (IListBlobItem item in container.ListBlobs(null, false))
     {
         if (item.GetType() == typeof(CloudBlockBlob))
         {
             CloudBlockBlob blob = (CloudBlockBlob)item;
             Console.WriteLine("Block blob of length { 0}: { 1}", blob.Properties.Length,blob.Uri);
         }
         else if (item.GetType() == typeof(CloudPageBlob))
         {
             CloudPageBlob pageBlob = (CloudPageBlob)item;
             Console.WriteLine("Page blob of length { 0}: { 1}", pageBlob.Properties.Length,pageBlob.Uri);
         }
         else if (item.GetType() == typeof(CloudBlobDirectory))
         {
             CloudBlobDirectory directory = (CloudBlobDirectory)item;
             Console.WriteLine("Directory: { 0}", directory.Uri);
         }
     }
 }
开发者ID:ftaran,项目名称:70-532,代码行数:21,代码来源:Program.cs

示例10: DumpContainer

        private static void DumpContainer(CloudBlobContainer container)
        {
            IEnumerable<IListBlobItem> list = container.ListBlobs();
            IEnumerator<IListBlobItem> enumerator = list.GetEnumerator();

            while (enumerator.MoveNext())
            {
                IListBlobItem item = (IListBlobItem)enumerator.Current;

                if (item.GetType() == typeof(CloudBlockBlob))
                {
                    CloudBlockBlob blob = (CloudBlockBlob)item;
                    Console.WriteLine("Block blob of Length: {0}", blob.Properties.Length);
                    Console.WriteLine("Uri: {0}", blob.Uri);
                }
                else
                {
                    Console.WriteLine("Unknown blob: ", item.ToString());
                }
            }
            Console.WriteLine();
        }
开发者ID:PeLoSTA,项目名称:Wpf_Cloud_01_Blobs,代码行数:22,代码来源:MainWindow.xaml.cs

示例11: GetLogItem

        public override LogItem GetLogItem(string baseAddress, string path)
        {
            if (_sasUrl == null)
            {
                return null;
            }

            if (String.IsNullOrWhiteSpace(path))
            {
                path = String.Empty;
            }

            path = path.TrimStart('/');

            var blobContainer = new CloudBlobContainer(new Uri(_sasUrl));

            var name = Path.GetFileName(path.TrimEnd('/').Replace("/", "\\"));

            if (path.EndsWith("/") || path == String.Empty)
            {
                var logItems = new List<LogItem>();
                var logDirectory = new LogItems()
                {
                    Url = baseAddress,
                    Name = name,
                    IsDirectory = true,
                    Path = path,
                    Root = Name,
                    Items = logItems
                };

                var blobs = blobContainer.ListBlobs(String.IsNullOrEmpty(path) ? null : path);
                foreach (var blob in blobs)
                {
                    if (blob is CloudBlockBlob)
                    {
                        var cloudBlockBlob = blob as CloudBlockBlob;
                        var innerName = Path.GetFileName(cloudBlockBlob.Name.TrimEnd('/').Replace("/", "\\"));
                        logItems.Add(new LogItem()
                        {
                            Name = innerName,
                            Size = cloudBlockBlob.Properties.Length,
                            Path = path + innerName,
                            Date = cloudBlockBlob.Properties.LastModified.HasValue ? (DateTime?)cloudBlockBlob.Properties.LastModified.Value.DateTime : null,
                            Url = baseAddress + innerName,
                            DownloadUrl = baseAddress + innerName + "&download=true"
                        });
                    }
                    else if (blob is CloudBlobDirectory)
                    {
                        var innerCloudBlobDirectory = blob as CloudBlobDirectory;
                        var innerPath = innerCloudBlobDirectory.Prefix;
                        var innerName = Path.GetFileName(innerPath.TrimEnd('/').Replace("/", "\\"));
                        logItems.Add(new LogItem()
                        {
                            IsDirectory = true,
                            Name = innerName,
                            Path = innerPath,
                            Url = baseAddress + innerName + "/"
                        });
                    }
                }

                return logDirectory;
            }

            var blockBlobReference = blobContainer.GetBlockBlobReference(path);
            if (blockBlobReference.Exists())
            {
                return new LogItem()
                {
                    Name = name,
                    Size = blockBlobReference.Properties.Length,
                    Path = path,
                    Date = blockBlobReference.Properties.LastModified.HasValue ? (DateTime?)blockBlobReference.Properties.LastModified.Value.DateTime : null,
                    Url = baseAddress,
                    DownloadUrl = blockBlobReference.Uri + _sas
                };
            }

            return null;
        }
开发者ID:joshka,项目名称:ThatLogExtension,代码行数:82,代码来源:StorageLogBrowser.cs

示例12: GetBlobList

 /// <summary>
 /// Returns a flattened list of <see cref="CloudBlockBlob"/> items from the specified <paramref name="CloudBlobContainer"/>.
 /// </summary>
 /// <param name="container"></param>
 /// <returns></returns>
 private static List<CloudBlockBlob> GetBlobList(CloudBlobContainer container)
 {
     var blobs = container
         .ListBlobs(useFlatBlobListing: true, blobListingDetails: BlobListingDetails.Metadata)
         .OfType<CloudBlockBlob>()
         .ToList();
     return blobs;
 }
开发者ID:GiscardBiamby,项目名称:AzzySync,代码行数:13,代码来源:SyncToBlobStorage.cs

示例13: UpdateLatestVersionFlags

        private void UpdateLatestVersionFlags(CloudBlobContainer container)
        {
            var blobsWithMetadata = container.ListBlobs().OfType<CloudBlockBlob>().Select(x => new
            {
                Blob = x,
                Metadata = _packageSerializer.ReadFromMetadata(x)
            }).ToList();

            foreach (var blobWithMetadata in blobsWithMetadata)
                blobWithMetadata.Metadata.IsLatestVersion = false;

            var latest = blobsWithMetadata.OrderBy(x => x.Metadata.Version).Reverse().First();
            latest.Metadata.IsLatestVersion = true;
            latest.Metadata.IsAbsoluteLatestVersion = true;

            foreach (var blobWithMetadata in blobsWithMetadata) 
                _packageSerializer.SaveToMetadata(blobWithMetadata.Metadata,blobWithMetadata.Blob);

        }
开发者ID:kevinhillinger,项目名称:Nuget.Server.AzureStorage,代码行数:19,代码来源:AzureServerPackageRepository+.cs

示例14: CopyBlockBlobAsync

        /// <summary>
        /// Gets a reference to a blob created previously, and copies it to a new blob in the same container.
        /// </summary>
        /// <param name="container">A CloudBlobContainer object.</param>
        /// <returns>A Task object.</returns>
        private static async Task CopyBlockBlobAsync(CloudBlobContainer container)
        {
            CloudBlockBlob sourceBlob = null;
            CloudBlockBlob destBlob = null;
            string leaseId = null;

            try
            {
                // Get a block blob from the container to use as the source.
                sourceBlob = container.ListBlobs().OfType<CloudBlockBlob>().FirstOrDefault();

                // Lease the source blob for the copy operation to prevent another client from modifying it.
                // Specifying null for the lease interval creates an infinite lease.
                leaseId = await sourceBlob.AcquireLeaseAsync(null);

                // Get a reference to a destination blob (in this case, a new blob).
                destBlob = container.GetBlockBlobReference("copy of " + sourceBlob.Name);

                // Ensure that the source blob exists.
                if (await sourceBlob.ExistsAsync())
                {
                    // Get the ID of the copy operation.
                    string copyId = await destBlob.StartCopyAsync(sourceBlob);

                    // Fetch the destination blob's properties before checking the copy state.
                    await destBlob.FetchAttributesAsync();

                    Console.WriteLine("Status of copy operation: {0}", destBlob.CopyState.Status);
                    Console.WriteLine("Completion time: {0}", destBlob.CopyState.CompletionTime);
                    Console.WriteLine("Bytes copied: {0}", destBlob.CopyState.BytesCopied.ToString());
                    Console.WriteLine("Total bytes: {0}", destBlob.CopyState.TotalBytes.ToString());
                    Console.WriteLine();
                }
            }
            catch (StorageException e)
            {
                Console.WriteLine(e.Message);
                Console.ReadLine();
                throw;
            }
            finally
            {
                // Break the lease on the source blob.
                if (sourceBlob != null)
                {
                    await sourceBlob.FetchAttributesAsync();

                    if (sourceBlob.Properties.LeaseState != LeaseState.Available)
                    {
                        await sourceBlob.BreakLeaseAsync(new TimeSpan(0));
                    }
                }
            }
        }
开发者ID:tamram,项目名称:storage-blob-dotnet-getting-started,代码行数:59,代码来源:Advanced.cs

示例15: QueryBlob

        /// <summary>
        /// Queries the BLOB.
        /// </summary>
        /// <param name="container">The container.</param>
        /// <param name="filterFunction">The filter function.</param>
        /// <param name="limitCount">The limit count.</param>
        /// <returns>IEnumerable&lt;CloudBlockBlob&gt;.</returns>
        public static IEnumerable<CloudBlockBlob> QueryBlob(CloudBlobContainer container, Func<CloudBlockBlob, bool> filterFunction, int? limitCount = null)
        {
            try
            {
                container.CheckNullObject("container");

                if (filterFunction != null)
                {
                    return limitCount == null ? container.ListBlobs().OfType<CloudBlockBlob>().Where(filterFunction) : container.ListBlobs().OfType<CloudBlockBlob>().Where(filterFunction).Take(limitCount.Value);
                }
                else
                {
                    return limitCount == null ? container.ListBlobs().OfType<CloudBlockBlob>() : container.ListBlobs().OfType<CloudBlockBlob>().Take(limitCount.Value);
                }
            }
            catch (Exception ex)
            {
                throw ex.Handle("QueryBlob", new { container = container == null ? null : container.Uri.ToString(), limitCount = limitCount });
            }
        }
开发者ID:rynnwang,项目名称:CommonSolution,代码行数:27,代码来源:AzureStorageManager.cs


注:本文中的Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer.ListBlobs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。