Exemplo n.º 1
0
        public async Task <bool> DeleteFile(string fileName)
        {
            MemoryStream        ms             = new MemoryStream();
            BlobManager         bm             = new BlobManager();
            CloudStorageAccount storageAccount = bm.InitializeAccount();
            CloudBlobClient     BlobClient     = storageAccount.CreateCloudBlobClient();
            CloudBlobContainer  container      = BlobClient.GetContainerReference("mysamplecontainer");

            try
            {
                if (await container.ExistsAsync())
                {
                    CloudBlob file = container.GetBlobReference(fileName);

                    if (await file.ExistsAsync())
                    {
                        await file.DeleteAsync();
                    }
                }
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemplo n.º 2
0
        public ActionResult DownLoadFile(string id)
        {
            //MemoryStream ms = new MemoryStream();
            //BlobManager bm = new BlobManager();
            //CloudStorageAccount storageAccount = bm.InitializeAccount();
            //CloudBlobClient BlobClient = storageAccount.CreateCloudBlobClient();
            //CloudBlobContainer c1 = BlobClient.GetContainerReference("mysamplecontainer");
            ////bool hasContainer = await c1.CreateIfNotExistsAsync();
            //if (c1.CreateIfNotExistsAsync())
            //{
            //    CloudBlob file = c1.GetBlobReference(id);

            //    if (file.ExistsAsync())
            //    {
            //        file.DownloadToStreamAsync(ms);
            //        Stream blobStream = file.OpenReadAsync().Result;
            //        return File(blobStream, file.Properties.ContentType, file.Name);
            //    }
            //    else
            //    {
            //        return Content("File does not exist");
            //    }
            //}
            //else
            //{
            //    return Content("Dir does not exist");
            //}


            MemoryStream        ms             = new MemoryStream();
            BlobManager         bm             = new BlobManager();
            CloudStorageAccount storageAccount = bm.InitializeAccount();

            CloudBlobClient    BlobClient = storageAccount.CreateCloudBlobClient();
            CloudBlobContainer c1         = BlobClient.GetContainerReference("mysamplecontainer");
            CloudBlob          file       = c1.GetBlobReference(id);

            file.DownloadToStreamAsync(ms);
            Stream blobStream = file.OpenReadAsync().Result;

            return(File(blobStream, file.Properties.ContentType, file.Name));
        }